Skip to content

Commit 860f6eb

Browse files
committed
feat(wokwi-hx711): arduino uno test
1 parent c5957b3 commit 860f6eb

File tree

7 files changed

+97
-0
lines changed

7 files changed

+97
-0
lines changed

.github/workflows/wokwi-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ jobs:
3434
- name: dht22-stm32
3535
path: wokwi-dht22/dht22-stm32
3636
scenario: dht22.test.yaml
37+
- name: hx711-uno
38+
path: wokwi-hx711/hx711-uno
39+
scenario: hx711.test.yaml
3740
- name: ili9341-uno
3841
path: wokwi-ili9341/lcd-uno
3942
scenario: ili9341.test.yaml

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ This repository contains a set of test projects for many Wokwi parts. The tests
1313
- [ESP32](./wokwi-dht22/dht22-esp32/)
1414
- [Raspberry Pi Pico](./wokwi-dht22/dht22-pico/)
1515
- [STM32L0](./wokwi-dht22/dht22-stm32/)
16+
- wokwi-hx711
17+
- [Arduino Uno](./wokwi-hx711/hx711-uno/)
1618
- wokwi-ili9341
1719
- [Arduino Uno](./wokwi-ili9341/lcd-uno/)
1820
- wokwi-lcd1602

wokwi-hx711/hx711-uno/diagram.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": 1,
3+
"author": "Claude Code",
4+
"editor": "wokwi",
5+
"parts": [
6+
{ "type": "wokwi-arduino-uno", "id": "uno", "top": 163.8, "left": 18.6, "attrs": {} },
7+
{ "type": "wokwi-hx711", "id": "hx711", "top": 0, "left": 100, "attrs": { "type": "5kg" } }
8+
],
9+
"connections": [
10+
[ "uno:GND.1", "hx711:GND", "black", [ "v-20", "*", "v0" ] ],
11+
[ "uno:3", "hx711:DT", "blue", [ "v-28.8", "h-168.8", "v-107.7" ] ],
12+
[ "uno:2", "hx711:SCK", "green", [ "v-19.2", "h-187.9", "v-107.4" ] ],
13+
[ "uno:5V", "hx711:VCC", "red", [ "v20", "h-178.6", "v-320.3" ] ]
14+
],
15+
"dependencies": {}
16+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: 'HX711 Load Cell Test'
2+
version: 1
3+
author: 'Claude Code'
4+
5+
steps:
6+
- wait-serial: 'HX711 test!'
7+
- wait-serial: 'HX711 initialized and tared'
8+
# Wait for first reading - should be near zero after taring
9+
- wait-serial: 'Raw: 0 Weight: 0.00 units'
10+
# Wait for second reading to confirm consistency
11+
- wait-serial: 'Raw: 0 Weight: 0.00 units'
12+
# Set load cell to a specific value (simulate weight applied)
13+
- set-control:
14+
part-id: hx711
15+
control: load
16+
value: 1050
17+
# Check reading with weight applied (441000 raw / 420 scale = 1050 units)
18+
- wait-serial: 'Raw: 441000 Weight: 1050.00 units'
19+
# Change weight to different value
20+
- set-control:
21+
part-id: hx711
22+
control: load
23+
value: 1680
24+
# Check new reading (705600 raw / 420 scale = 1680 units)
25+
- wait-serial: 'Raw: 705600 Weight: 1680.00 units'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[env:uno]
2+
platform = atmelavr
3+
board = uno
4+
framework = arduino
5+
lib_deps =
6+
bogde/HX711@^0.7.5

wokwi-hx711/hx711-uno/src/main.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <Arduino.h>
2+
#include "HX711.h"
3+
4+
// HX711 circuit wiring
5+
const int LOADCELL_DOUT_PIN = 3;
6+
const int LOADCELL_SCK_PIN = 2;
7+
8+
HX711 scale;
9+
10+
void setup() {
11+
Serial.begin(9600);
12+
Serial.println(F("HX711 test!"));
13+
14+
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
15+
16+
// Set scale factor (calibration value)
17+
// For the 5kg load cell simulation, raw values range from 0-2100
18+
scale.set_scale(420.0); // This gives us readings in a 0-5 range for 0-2100 raw
19+
20+
// Tare the scale to zero
21+
scale.tare();
22+
23+
Serial.println(F("HX711 initialized and tared"));
24+
}
25+
26+
void loop() {
27+
delay(500);
28+
29+
if (scale.is_ready()) {
30+
long rawValue = scale.get_value();
31+
float weight = scale.get_units();
32+
33+
Serial.print(F("Raw: "));
34+
Serial.print(rawValue);
35+
Serial.print(F(" Weight: "));
36+
Serial.print(weight, 2);
37+
Serial.println(F(" units"));
38+
} else {
39+
Serial.println(F("HX711 not ready"));
40+
}
41+
}

wokwi-hx711/hx711-uno/wokwi.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[wokwi]
2+
version = 1
3+
firmware = '.pio/build/uno/firmware.hex'
4+
elf = '.pio/build/uno/firmware.elf'

0 commit comments

Comments
 (0)