ADC and I/O Ports

Hi,
I am using the Arduino programming environment with a RAK3172.
I noticed that when I enable one ADC channel by “analogRead(ADC1)” the other analog input ports like ADC3 or ADC4 also seem to switch to ADC mode. Did I miss something in your docu or is it possible to use just one ADC input and the others as I/O ports?

Regards
Jan

Hi @JBurg ,

That is not a correct behavior. If ADC1 is the only intended channel to be used, that should only be the one enabled. Can you please share me the firmware version you use and also the test sketch/code you use on your evaluation?

Hi carlrowan,
below is my Arduino code with the I/O ports PB2 and BB12. These stay at about 1.8 V and don’t change with digitalWrite.
How can I get the firmware version? The command AT+VERSION from your RAK_SERIAL_PORT_TOOL_V1.2.1 is not supported.

Regards
Jan

uint8_t LEDW1 = PA0; /yellow LED bank 1/
uint8_t LEDW2 = PA1; /yellow LED bank 2/
uint8_t LEDA1 = PA8; /red LED bank 1/
uint8_t LEDA2 = PA9; /red LED bank 2/
uint8_t LEDR = PB2; /RGB LED red/
uint8_t LEDG = PB12; /RGB LED green/
uint8_t LEDB = PB5; /RGB LED blue/
uint8_t Addr1 = PA7; /address switch output 2^0/
uint8_t Addr2 = PA6; /address switch output 2^1/
uint8_t Addr4 = PA5; /address switch output 2^2/
uint8_t Addr8 = PA4; /address switch output 2^3/
uint8_t ADC1 = WB_A1; /ADC input for supply voltage/
long startTime;
double myFreq = 868000000;
uint16_t sf = 12, bw = 0, cr = 0, preamble = 8, txPower = 22;
uint8_t Status;
uint16_t Timer;
uint8_t Address;
uint8_t Address1;
#define Timeout 100
#define BattMin 310
bool RxDone = false;

void recv_cb(rui_lora_p2p_recv_t data) /Rx callback/
{
RxDone = true;
char Buff[92];
sprintf(Buff, “Incoming message, length: %d, RSSI: %d, SNR: %d, %s\n”, data.BufferSize, data.Rssi, data.Snr, data.Buffer);
Serial.println(Buff); /send Rx confirmation via UART/
if (data.Buffer[0] == ‘#’)
{
Address1 = data.Buffer[1] - 48;
if (Address1 > 9) /for hex numbers A to F/
Address1 -= 7;
if (Address == Address1)
{
if ((data.Buffer[2] == ‘0’) && (Timer > Timeout)) /no warning/alarm/
Status = 1;
else if ((data.Buffer[2] == ‘W’) && (Timer > Timeout)) /warning/
Status = 2;
else if (data.Buffer[2] == ‘A’) /alarm/
Status = 3;
}
else
Status = 0;
}
}
void send_cb(void) /Tx callback/
{
Serial.printf(“P2P set Rx mode %s\r\n”, api.lorawan.precv(65534) ? “OK” : “ERROR”); /send Tx status via UART and return to Rx/
}
void setup()
{
// initialize serial communication at 115200 bits per second
Serial.begin(115200);
Serial.println(“VM40-R2 Initialization”);
// initialize the LED pins as an output
pinMode(LEDW1, OUTPUT);
pinMode(LEDW2, OUTPUT);
pinMode(LEDA1, OUTPUT);
pinMode(LEDA2, OUTPUT);
pinMode(LEDR, OUTPUT);
pinMode(LEDG, OUTPUT);
pinMode(LEDB, OUTPUT);
digitalWrite(LEDR, HIGH);
digitalWrite(LEDG, LOW); /green status LED on/
digitalWrite(LEDB, HIGH);
pinMode(Addr1, INPUT_PULLUP);
pinMode(Addr2, INPUT_PULLUP);
pinMode(Addr4, INPUT_PULLUP);
pinMode(Addr8, INPUT_PULLUP);
startTime = millis();
Serial.println(“P2P Start”);
Serial.printf(“Hardware ID: %s\r\n”, api.system.chipId.get().c_str());
Serial.printf(“Model ID: %s\r\n”, api.system.modelId.get().c_str());
Serial.printf(“RUI API Version: %s\r\n”, api.system.apiVersion.get().c_str());
Serial.printf(“Firmware Version: %s\r\n”, api.system.firmwareVersion.get().c_str());
Serial.printf(“AT Command Version: %s\r\n”, api.system.cliVersion.get().c_str());
Serial.printf(“Set Node device work mode %s\r\n”, api.lorawan.nwm.set(0) ? “OK” : “ERROR”);
Serial.printf(“Set P2P mode frequency %3.3f: %s\r\n”, (myFreq / 1e6), api.lorawan.pfreq.set(myFreq) ? “OK” : “ERROR”);
Serial.printf(“Set P2P mode spreading factor %d: %s\r\n”, sf, api.lorawan.psf.set(sf) ? “OK” : “ERROR”);
Serial.printf(“Set P2P mode bandwidth %d: %s\r\n”, bw, api.lorawan.pbw.set(bw) ? “OK” : “ERROR”);
Serial.printf(“Set P2P mode code rate 4/%d: %s\r\n”, (cr + 5), api.lorawan.pcr.set(0) ? “OK” : “ERROR”);
Serial.printf(“Set P2P mode preamble length %d: %s\r\n”, preamble, api.lorawan.ppl.set(8) ? “OK” : “ERROR”);
Serial.printf(“Set P2P mode tx power %d: %s\r\n”, txPower, api.lorawan.ptp.set(22) ? “OK” : “ERROR”);
api.lorawan.registerPRecvCallback(recv_cb);
api.lorawan.registerPSendCallback(send_cb);
Serial.printf(“P2P set Rx mode %s\r\n”, api.lorawan.precv(65534) ? “OK” : “ERROR”);
Timer = 0; /reset timeout/
}

void loop()
{
Address = 15 - (digitalRead(Addr1) + (digitalRead(Addr2) << 1) + (digitalRead(Addr4) << 2) + (digitalRead(Addr8) << 3)); /read out address switch/
int Batt = analogRead(ADC1);
if (Status == 1) /no warning/alarm/
{
digitalWrite(LEDW1, LOW); /all warning/alarm LEDs off/
digitalWrite(LEDW2, LOW);
digitalWrite(LEDA1, LOW);
digitalWrite(LEDA2, LOW);
}
else if (Status == 2) /warning/
{
digitalWrite(LEDA1, LOW);
digitalWrite(LEDA2, LOW);
digitalWrite(LEDW1, HIGH);
digitalWrite(LEDW2, LOW);
delay(100);
digitalWrite(LEDW1, LOW);
digitalWrite(LEDW2, HIGH);
}
else if (Status == 3) /alarm/
{
digitalWrite(LEDW1, LOW);
digitalWrite(LEDW2, LOW);
digitalWrite(LEDA1, HIGH);
digitalWrite(LEDA2, LOW);
delay(100);
digitalWrite(LEDA1, LOW);
digitalWrite(LEDA2, HIGH);
}
delay(100);
if (Batt < BattMin) /if battery empty/
{
digitalWrite(LEDR, HIGH);
digitalWrite(LEDG, HIGH);
digitalWrite(LEDB, LOW); /blue status LED on/
}
if (Status && RxDone) /after receiving a status message/
{
RxDone = false;
Timer = 0;
if (Batt >= BattMin) /if battery OK/
{
digitalWrite(LEDR, HIGH);
digitalWrite(LEDG, LOW); /green status LED on/
digitalWrite(LEDB, HIGH);
}
}
if (++Timer == Timeout)
{
Timer = Timeout + 1;
digitalWrite(LEDW1, LOW); /all warning/alarm LEDs off/
digitalWrite(LEDW2, LOW);
digitalWrite(LEDA1, LOW);
digitalWrite(LEDA2, LOW);
if (Batt >= BattMin) /if battery OK/
{
digitalWrite(LEDR, LOW); /red status LED on/
digitalWrite(LEDG, HIGH);
digitalWrite(LEDB, HIGH);
}
Status = 0;
}
}