I ended up at the hospital, so it will take a few days until I can get you the code running on the core, but it is basically just an analogRead and using millis() to calculate a 1000ms delay between readings, then using the publish function to send the reading to me,
As far as I can see, nothing happens, except the reading suddenly go down and back up again. An oscilloscope does not detect anything happen either. Can’t see a change on the 5V, 3V3 or 3V3* line, and the voltage on the analog pin the sensor is connected to does not jump either.
#define TMP36pin A7 // Pin with the TMP36 sensor connected
#define readTMP36trot 1000 // Time in milliseconds between temperature readings
double temperature = 0; // Current temperature
void setup()
{
Spark.variable("tempReading", &temperature, DOUBLE);
}
void loop()
{
readTMP36(); // Read from the temperature sensor and set the temperature variable
}
unsigned long readTMP36last = 0;
void readTMP36()
{
unsigned int now = millis();
if (now - readTMP36last < readTMP36trot) return;
readTMP36last = now;
int analogReading = analogRead(TMP36pin);
temperature = ((((analogReading*3.3)/4095.0)-0.5)*100.0); // Check analog input and calculate the temperature
Spark.publish("debug", String(analogReading).c_str());
}
This is the code running, and there isn’t much to it.
I get odd readings occasionally (maybe once a second = 1 in 5,000 readings) when I use the Sparkfun microphone breakout board. Resistor, thermistor and photoresistor measurements are rock steady so I assume the problem lies in the electret microphone electronics. I filter the dodgy readings out on the fly. I guess that the transient after the spike is the op amp recovering. The board is battery powered and there is a 10uF capacitor across the power supply and 10nF capacitor between the ADC and ground.
Spark fun microphone readings sampled at 200uSec intervals.
The effect is reproducible. Here is a different Spark, a different Sparkfun breakout board and with the circuit on a breadboard rather than soldered on a stripboard. This time there is an audio test tone so that the signal is larger. The glitch shouts out of an fft.
The code is simple:
else if (UDPin[1]=='a'){
//update sound
for (i=-50;i<DATALEN;i++){
delayMicroseconds(160);
if (i >= 0) dynamicData[i]=analogRead(micPin);
else analogRead(micPin);
}
udp.write((unsigned char*)&dynamicData[0],sizeof(dynamicData));
}
There are 50 dummy reads before data are collected for real to get past any startup transients.