Hey all,
I’m trying out the RAK4360 with the RAK5811 interface mounted on a WisBlock.
I have been plugging it into my laptop, a 2013 macbook pro. Today I had some very strange behaviour from the setup. I wonder if anyone could suggest what is going on?
- It runs very warm. It is quite warm to touch.
- My computer shut down, as if the device was using too much current or caused an overvoltage at the USB port.
- The 5811 will turn off and I don’t see why (with nothing in the code to pull the pin low). I can see that it is turned off in the sense that 0.08V is present where it should be outputting 3.3V.
-The 5811 will sometimes emit a wandering low voltage of about 163mV where it should emit 3.3V. Unplugging the unit and plugging it in again seems to reset this. It is sometimes, but not always, triggered by flashing the device.
I’ve had a few errors that the 4630 is unavailable to flash as well. Unplugging it and plugging it in seems to reset it.
I used the example code to sense a voltage from the 5811 (RAK58110-5V.ino in the Arduino IDE) and modified the code. I’ll put it below.
Also, I saw that the internal MCU, the nRF52840 has a 12 bit ADC and we can add a line to start using 12 bit instead of the default 10 bit, so I tried that. It’s stable when I apply 3.3V from the 5811 into A1. But when I try to measure temperature with a 10K thermistor I know works well, in a voltage divider, I get a lot of wander and drift. Here in the chart you can see when I pinch the (ntc) thermistor with my finger. The signal does drop in a logarithmic shape each time (4 times). But there are some strange things happening too - there is a drop, and a lot of drift up and down. Is this just noise from a low quality ADC, or is something deeper going on?
Sorry that’s a lot of stuff all at once! But I wonder is there is some single source like a problem with the power supply? I don’t want to give up on LoRaWan or Wisboard but I can’t use the system like this.
/**
* This was:
* @file RAK5811_0-5V.ino
* @author rakwireless.com
* @brief 0 to 5V analog input example.
* @version 0.1
* @date 2020-07-28
* @copyright Copyright (c) 2020
*
* It was edited by James Douglas, 2022-03-25. Then used for temperature sensing.
*/
#include <Arduino.h>
#include <Adafruit_TinyUSB.h>
#define NUMSAMPLES 32
//thermistor stuff
// resistance at 25 degrees C
#define THERMISTORNOMINAL 10000
// temp. for nominal resistance (almost always 25 C)
#define TEMPERATURENOMINAL 25
// how many samples to take and average, more takes longer
// but is more 'smooth'
#define NUMSAMPLES 5
// The beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3950
// the value of the 'other' resistor
#define SERIESRESISTOR 10000
void setup()
{
Serial.begin(115200);
/* WisBLOCK 5811 Power On*/
pinMode(WB_IO1, OUTPUT);
digitalWrite(WB_IO1, HIGH);
pinMode(WB_A1, INPUT_PULLDOWN);
analogReference(AR_INTERNAL_3_0);
analogOversampling(128);
analogReadResolution(12); //default is a 10 bit adc. But actually the nRF52840 has a 12 bit adc.
}
void loop()
{
getADC();
Serial.println(calcTemp(getADC()));
delay(2000);
}
float calcTemp(int adc){
// convert the value to resistance
float resistance;
resistance = SERIESRESISTOR * (4095.0 / adc - 1.0);//4095 is the number of levels on the adc
float steinhart;
steinhart = resistance / THERMISTORNOMINAL; // (R/Ro)
steinhart = log(steinhart); // ln(R/Ro)
steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro)
steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
steinhart = 1.0 / steinhart; // Invert
steinhart -= 273.15; // convert to C
// Particle.publish("Temperature: ", String(steinhart)); //This is just for troubleshooting.
return steinhart;
}
int getADC(){
int ADCReadingsAcc = 0; //Use this to add all the ADC readings together.
int averageADCReadings; //Use this to average of all the adc readings
float ADCVoltage; //Use this to store the voltage reaching MCU.
float originalVoltage; //Use this to store the voltage reaching the 5811.
//The 5811 is just an op amp. It takes in up to 5V and outputs only up to 3.0V. It's just meant to take in 5V and make that readable with the ADC on the RAK.
//Plus it gives you a little spring terminal block to attach stuff to.
for (int i = 0; i < NUMSAMPLES; i++)
{
ADCReadingsAcc += analogRead(WB_A1); //take a reading from the adc and accumulate them all.
}
averageADCReadings = ADCReadingsAcc / NUMSAMPLES;
ADCVoltage = averageADCReadings * 3.0 / 1024; //max 3V, 10bit ADC
originalVoltage = ADCVoltage / 0.6; //The 5811 just cuts the 5V max signal down to max 3.0V so the ADC can handle it. Here we calculate backwards to get the original voltage.
//Serial.println(averageADCReadings);
return averageADCReadings;
}
/*
float measuretemp()
{
float average;
// take N samples in a row, with a slight delay
for (i=0; i< NUMSAMPLES; i++)
{
samples[i] = analogRead(THERMISTORPIN);
delay(10);
}
// average all the samples out
average = 0;
for (i=0; i< NUMSAMPLES; i++)
{
average += samples[i];
}
average /= NUMSAMPLES;
// convert the value to resistance
float resistance;
resistance = SERIESRESISTOR * (4095.0 / average - 1.0);//4095 is the number of levels on the adc
float steinhart;
steinhart = resistance / THERMISTORNOMINAL; // (R/Ro)
steinhart = log(steinhart); // ln(R/Ro)
steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro)
steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
steinhart = 1.0 / steinhart; // Invert
steinhart -= 273.15; // convert to C
// Particle.publish("Temperature: ", String(steinhart)); //This is just for troubleshooting.
return steinhart;
}
*/