Description
Describe the bug
analogRead(A0) - is returning a value that does not fit within 10 bits, like 3349. Guessing that analogRead
is returning 12 bits, whereas the document:
https://docs.arduino.cc/language-reference/en/functions/analog-io/analogRead/
says that it should default to 10 bit resolution.
analogReadResolution(int bit) - is not defined within the system (i.e. compile error)
Target board + cli verbose compilation output
Arduino Zephyr - GIGA...
Optional: attach the sketch
Started with the AnalogInput.ino example sketch, with a few edits to use the built in LED and prints out the
values returned, if the value changed from the previous call.
Also checked for Serial input and used the input for which analog pin to use 0 is A0...
/*
Analog Input
Demonstrates analog input by reading an analog sensor on analog pin 0 and
turning on and off a light emitting diode(LED) connected to digital pin 13.
The amount of time the LED will be on and off depends on the value obtained
by analogRead().
The circuit:
- potentiometer
center pin of the potentiometer to the analog input 0
one side pin (either one) to ground
the other side pin to +5V
- LED
anode (long leg) attached to digital output 13 through 220 ohm resistor
cathode (short leg) attached to ground
- Note: because most Arduinos have a built-in LED attached to pin 13 on the
board, the LED is optional.
created by David Cuartielles
modified 30 Aug 2011
By Tom Igoe
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInput
*/
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = LED_BUILTIN; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
int sensorValuePrev = -1;
void setup() {
// declare the ledPin as an OUTPUT:
//analogReadResolution(10);
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
if (sensorValue != sensorValuePrev) {
Serial.println(sensorValue);
sensorValuePrev = sensorValue;
}
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
if (Serial.available()) {
int pin_num = Serial.parseInt();
while (Serial.available()) Serial.read();
static const int analog_pins[] = {A0, A1, A2, A3, A4, A5, A6, A7/*, A8, A9, A10, A11*/};
sensorPin = analog_pins[pin_num];
Serial.print("New pin A");
Serial.print(pin_num);
Serial.print(" : ");
Serial.println(sensorPin);
sensorValuePrev = -1;
}
}
The above works for A0-A7
uncommenting A8-A11, gives compile errors.
C:\Users\kurte\Documents\Arduino\hardware\arduino-git\ArduinoCore-zephyr\variants\arduino_giga_r1_m7/pure_analog_pins.h:40:13: error: call to 'PureAnalogPin::operator int' declared with attribute error: Change me to a #define
40 | #define A8 A8_PURE
| ^~~~~~~
C:\Users\kurte\Documents\Arduino\hardware\arduino-git\ArduinoCore-zephyr\variants\arduino_giga_r1_m7/pure_analog_pins.h:40:13: note: in definition of macro 'A8'
40 | #define A8 A8_PURE
| ^~~~~~~
C:\Users\kurte\Documents\Arduino\hardware\arduino-git\ArduinoCore-zephyr\variants\arduino_giga_r1_m7/pure_analog_pins.h:41:13: error: call to 'PureAnalogPin::operator int' declared with attribute error: Change me to a #define
41 | #define A9 A9_PURE
| ^~~~~~~
C:\Users\kurte\Documents\Arduino\hardware\arduino-git\ArduinoCore-zephyr\variants\arduino_giga_r1_m7/pure_analog_pins.h:41:13: note: in definition of macro 'A9'
41 | #define A9 A9_PURE
| ^~~~~~~
C:\Users\kurte\Documents\Arduino\hardware\arduino-git\ArduinoCore-zephyr\variants\arduino_giga_r1_m7/pure_analog_pins.h:42:14: error: call to 'PureAnalogPin::operator int' declared with attribute error: Change me to a #define
42 | #define A10 A10_PURE
| ^~~~~~~~
C:\Users\kurte\Documents\Arduino\hardware\arduino-git\ArduinoCore-zephyr\variants\arduino_giga_r1_m7/pure_analog_pins.h:42:14: note: in definition of macro 'A10'
Will look at later...