Skip to content

Commit d878e48

Browse files
committed
feat(tests): add ADC potentiometer test and related configurations
1 parent bb5902b commit d878e48

11 files changed

+282
-0
lines changed

tests/validation/adc/adc.ino

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <Arduino.h>
2+
#include <unity.h>
3+
4+
#define BTN 0
5+
#define LED 4
6+
7+
#if CONFIG_IDF_TARGET_ESP32P4
8+
#define POT_PIN 53
9+
#else
10+
#define POT_PIN 2
11+
#endif
12+
13+
14+
15+
void setUp(void) {}
16+
17+
void tearDown(void) {}
18+
19+
void test_adc_potentiometer(void) {
20+
Serial.println("ADC potentiometer test START");
21+
22+
// Configure ADC
23+
analogReadResolution(12); // Set ADC resolution to 12 bits (0-4095)
24+
analogSetAttenuation(ADC_11db); // Set attenuation for full 3.3V range
25+
26+
Serial.println("Reading ADC values from potentiometer on GPIO2");
27+
28+
// Take multiple readings to test different potentiometer positions
29+
for (int i = 0; i < 5; i++) {
30+
int adcValue = analogRead(POT_PIN);
31+
float voltage = (adcValue * 3.3) / 4095.0;
32+
33+
Serial.print("ADC Reading ");
34+
Serial.print(i + 1);
35+
Serial.print(": ");
36+
Serial.print(adcValue);
37+
Serial.print(" (");
38+
Serial.print(voltage, 2);
39+
Serial.println("V)");
40+
41+
// Test that ADC reading is within valid range
42+
TEST_ASSERT_GREATER_OR_EQUAL(0, adcValue);
43+
TEST_ASSERT_LESS_OR_EQUAL(4095, adcValue);
44+
45+
delay(1000); // Wait 1 second between readings
46+
}
47+
48+
Serial.println("ADC potentiometer test completed successfully");
49+
}
50+
51+
52+
void setup() {
53+
Serial.begin(115200);
54+
while (!Serial) {
55+
;
56+
}
57+
58+
UNITY_BEGIN();
59+
RUN_TEST(test_adc_potentiometer);
60+
UNITY_END();
61+
62+
Serial.println("ADC test END");
63+
}
64+
65+
void loop() {}

tests/validation/adc/ci.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"platforms": {
3+
"hardware": false,
4+
"qemu": false,
5+
"wokwi": true
6+
}
7+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"version": 1,
3+
"author": "Jakub Andrýsek",
4+
"editor": "wokwi",
5+
"parts": [
6+
{ "type": "board-esp32-devkit-c-v4", "id": "esp", "top": 0, "left": 0, "attrs": {} },
7+
{
8+
"type": "wokwi-potentiometer",
9+
"id": "pot1",
10+
"top": 143.8,
11+
"left": 165.3,
12+
"rotate": 90,
13+
"attrs": {}
14+
}
15+
],
16+
"connections": [
17+
[ "esp:TX", "$serialMonitor:RX", "", [] ],
18+
[ "esp:RX", "$serialMonitor:TX", "", [] ],
19+
[ "pot1:GND", "esp:GND.2", "black", [ "h-48", "v-143.82" ] ],
20+
[ "pot1:VCC", "esp:5V", "red", [ "h0" ] ],
21+
[ "esp:2", "pot1:SIG", "green", [ "h0" ] ]
22+
],
23+
"dependencies": {}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"version": 1,
3+
"author": "Jakub Andrýsek",
4+
"editor": "wokwi",
5+
"parts": [
6+
{ "type": "board-esp32-c3-devkitm-1", "id": "esp", "top": 0, "left": 0, "attrs": {} },
7+
{
8+
"type": "wokwi-potentiometer",
9+
"id": "pot1",
10+
"top": 143.8,
11+
"left": 165.3,
12+
"rotate": 90,
13+
"attrs": {}
14+
}
15+
],
16+
"connections": [
17+
[ "esp:TX", "$serialMonitor:RX", "", [] ],
18+
[ "esp:RX", "$serialMonitor:TX", "", [] ],
19+
[ "pot1:GND", "esp:GND.2", "black", [ "h-48", "v-143.82" ] ],
20+
[ "pot1:VCC", "esp:3V3", "red", [ "h0" ] ],
21+
[ "esp:2", "pot1:SIG", "green", [ "h0" ] ]
22+
],
23+
"dependencies": {}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"version": 1,
3+
"author": "Jakub Andrýsek",
4+
"editor": "wokwi",
5+
"parts": [
6+
{ "type": "board-esp32-c6-devkitc-1", "id": "esp", "top": 0, "left": 0, "attrs": {} },
7+
{
8+
"type": "wokwi-potentiometer",
9+
"id": "pot1",
10+
"top": 143.8,
11+
"left": 165.3,
12+
"rotate": 90,
13+
"attrs": {}
14+
}
15+
],
16+
"connections": [
17+
[ "esp:TX", "$serialMonitor:RX", "", [] ],
18+
[ "esp:RX", "$serialMonitor:TX", "", [] ],
19+
[ "pot1:GND", "esp:GND.2", "black", [ "h-48", "v-143.82" ] ],
20+
[ "pot1:VCC", "esp:3V3", "red", [ "h0" ] ],
21+
[ "esp:2", "pot1:SIG", "green", [ "h0" ] ]
22+
],
23+
"dependencies": {}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"version": 1,
3+
"author": "Jakub Andrýsek",
4+
"editor": "wokwi",
5+
"parts": [
6+
{ "type": "board-esp32-h2-devkitm-1", "id": "esp", "top": 0, "left": 0, "attrs": {} },
7+
{
8+
"type": "wokwi-potentiometer",
9+
"id": "pot1",
10+
"top": 143.8,
11+
"left": 165.3,
12+
"rotate": 90,
13+
"attrs": {}
14+
}
15+
],
16+
"connections": [
17+
[ "esp:TX", "$serialMonitor:RX", "", [] ],
18+
[ "esp:RX", "$serialMonitor:TX", "", [] ],
19+
[ "pot1:GND", "esp:GND.2", "black", [ "h-48", "v-143.82" ] ],
20+
[ "pot1:VCC", "esp:3V3", "red", [ "h0" ] ],
21+
[ "esp:2", "pot1:SIG", "green", [ "h0" ] ]
22+
],
23+
"dependencies": {}
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"version": 1,
3+
"author": "Jakub Andrýsek",
4+
"editor": "wokwi",
5+
"parts": [
6+
{ "type": "board-esp32-p4-function-ev", "id": "esp", "top": 0, "left": 0, "attrs": {} },
7+
{ "type": "wokwi-potentiometer", "id": "pot1", "top": -115.4, "left": 261.3, "attrs": {} }
8+
],
9+
"connections": [
10+
[ "esp:37", "$serialMonitor:RX", "", [] ],
11+
[ "esp:38", "$serialMonitor:TX", "", [] ],
12+
[ "pot1:GND", "esp:GND.2", "black", [ "h-48", "v-143.82" ] ],
13+
[ "pot1:VCC", "esp:3V3", "red", [ "h0" ] ],
14+
[ "esp:53", "pot1:SIG", "green", [ "h0" ] ],
15+
[ "esp:5V.2", "pot1:VCC", "red", [ "v-27.92", "h119.07" ] ]
16+
],
17+
"dependencies": {}
18+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"version": 1,
3+
"author": "Jakub Andrýsek",
4+
"editor": "wokwi",
5+
"parts": [
6+
{ "type": "board-esp32-s2-devkitm-1", "id": "esp", "top": 0, "left": 0, "attrs": {} },
7+
{
8+
"type": "wokwi-potentiometer",
9+
"id": "pot1",
10+
"top": 143.8,
11+
"left": 165.3,
12+
"rotate": 90,
13+
"attrs": {}
14+
}
15+
],
16+
"connections": [
17+
[ "esp:TX", "$serialMonitor:RX", "", [] ],
18+
[ "esp:RX", "$serialMonitor:TX", "", [] ],
19+
[ "pot1:GND", "esp:GND.2", "black", [ "h-48", "v-143.82" ] ],
20+
[ "pot1:VCC", "esp:3V3", "red", [ "h0" ] ],
21+
[ "esp:2", "pot1:SIG", "green", [ "h0" ] ]
22+
],
23+
"dependencies": {}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"version": 1,
3+
"author": "Jakub Andrýsek",
4+
"editor": "wokwi",
5+
"parts": [
6+
{ "type": "board-esp32-s3-devkitc-1", "id": "esp", "top": 0, "left": 0, "attrs": {} },
7+
{
8+
"type": "wokwi-potentiometer",
9+
"id": "pot1",
10+
"top": 143.8,
11+
"left": 165.3,
12+
"rotate": 90,
13+
"attrs": {}
14+
}
15+
],
16+
"connections": [
17+
[ "esp:TX", "$serialMonitor:RX", "", [] ],
18+
[ "esp:RX", "$serialMonitor:TX", "", [] ],
19+
[ "pot1:GND", "esp:GND.2", "black", [ "h-48", "v-143.82" ] ],
20+
[ "pot1:VCC", "esp:5V", "red", [ "h0" ] ],
21+
[ "esp:2", "pot1:SIG", "green", [ "h0" ] ]
22+
],
23+
"dependencies": {}
24+
}

tests/validation/adc/scenario.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: ADC potentiometer test
2+
version: 1
3+
author: Jakub Andrysek ([email protected])
4+
5+
steps:
6+
#### ADC potentiometer test
7+
- wait-serial: "ADC potentiometer test START"
8+
- wait-serial: "Reading ADC values from potentiometer on GPIO2"
9+
10+
# Set potentiometer to different positions and wait for readings
11+
- set-control:
12+
part-id: pot1
13+
control: position
14+
value: 0.0
15+
- wait-serial: "ADC Reading 1:"
16+
17+
- set-control:
18+
part-id: pot1
19+
control: position
20+
value: 0.25
21+
- wait-serial: "ADC Reading 2:"
22+
23+
- set-control:
24+
part-id: pot1
25+
control: position
26+
value: 0.5
27+
- wait-serial: "ADC Reading 3:"
28+
29+
- set-control:
30+
part-id: pot1
31+
control: position
32+
value: 0.75
33+
- wait-serial: "ADC Reading 4:"
34+
35+
- set-control:
36+
part-id: pot1
37+
control: position
38+
value: 1.0
39+
- wait-serial: "ADC Reading 5:"
40+
41+
- wait-serial: "ADC potentiometer test completed successfully"
42+
43+
- wait-serial: "ADC test END"

0 commit comments

Comments
 (0)