Odd analog readings (part 2)

Yes it was from a direct result of this thread :slight_smile: See first post.

I’m guessing you’ll want to stay to the high end 13.5. Having it set to 41.5 probably yields 13.5 max anyway so I don’t know if there will be much change in how it responds. Comparing to the old way of 41.5 single channel/conversion might be interesting though.

@BDub correct after trying out with 1.5, 7.5 & 13.5, readings are pretty much similar to 41.5 sampling time. But I haven’t tested it comprehensively as you did in your first post. Would you like to repeat the test and see how the use of Dual ADC compares with the single ADC in terms of input impedence and publish the result.
Thanks,
Satish.

@BDub, Default sampling time is now set to 7.5 and added a new setADCSampleTime() which can be called in setup() to override the default ADC Sampling time.

Ahh cool! I was totally going to suggest that since it seems like some people might need faster sampling and can take care of making sure the input impedance is low enough to get good readings. I’ll try to get some testing in tonight.

I like the new setADCSampleTime() function–looks great!

I tried the new master tonight with the 7cycles5 default rate and that worked great for my simple test.

3 Likes

Well it was very nice to return home and find that the ADC issues are solved - thanks guys. The new code gives excellent results with my 50Hz measurements so I can get back to the Energy Monitor development.

I’m getting around a 35uS conversion time with 1_5 set in setADCSampleTime() and 40uS with the default 7_5 so there is not a lot of difference. If I want faster sampling for my next project I’ll go back to the pre-DMA version of the code which was much faster but make sure I take care with input impedance.

3 Likes

Can someone help me out with the circuit of the temperature sensor interfaced with spark core? My program is correct but some problem in circuit.? Reply ASAP

Thanks in Advance

Hi @anirudh,

Can you post a picture or diagram of your circuit? What do you need help with?

Thanks,
David

Hello @Dave

I’m doing basing on this circuit, I’ve connected everything, I need the code of it, REPLY ASAP

Thanks in Advance

@anirudh Hi there! The code can be found here…
http://docs.spark.io/examples/#measuring-the-temperature

// -----------------
// Read temperature
// -----------------

// Create a variable that will store the temperature value
int temperature = 0;

void setup()
{
  // Register a Spark variable here
  Spark.variable("temperature", &temperature, INT);

  // Connect the temperature sensor to A7 and configure it
  // to be an input
  pinMode(A7, INPUT);
}

void loop()
{
  // Keep reading the temperature so when we make an API
  // call to read its value, we have the latest one
  temperature = analogRead(A7);
}

How to read the data:

voltage = (sensor reading x 3.3)/4095
Temperature (in Celsius) = (voltage - 0.5) X 100

The API request will look something like this:
GET /v1/devices/{DEVICE_ID}/temperature

# EXAMPLE REQUEST IN TERMINAL
# Core ID is 0123456789abcdef
# Your access token is 123412341234
curl -G https://api.spark.io/v1/devices/0123456789abcdef/temperature -d access_token=123412341234

Since this is a GET request you can also just use a URL like this in your browser:
https://api.spark.io/v1/devices/0123456789abcdef/temperature&access_token=123412341234

Perhaps you have this already? What issues are you having?

2 Likes

Hi @anirudh,

Looks like @Bdub got back to you quickly, but just jumping in too to say Hi. :slight_smile:

edit: for reference, I’m in the CST time zone and although I often am online, I won’t necessarily be online at midnight for an asap response. :slight_smile:

Thanks,
David

2 Likes

Hey @Dave :smile:

Since I got your reply as soon as i posted the problem, In my next thing I said reply ASAP.

Otherwise I wouldn’t have said it :stuck_out_tongue:

Hail Spark team :smile:

1 Like

Ahh, haha, sorry! :slight_smile:

@anirudh so are you all set now reading temperature or are you still working out some issues?

2 Likes

I’m also having trouble reading temperature from my Spark Core. I have a Spark Maker kit and am using the TMP36 sensor and one of the included 10nF caps. My circuit is set up just as in the Spark documentation:
http://docs.spark.io/examples/#measuring-the-temperature

I’m using the Tinker firmware, and my raw analog readings vary between 700 and 800 (which equates to temps of 43F to 58F). I’m testing in my house, and a digital thermometer next to my Spark Core reads a constant 77F.

Are such wild reading expected or normal with the Tinker firmware?

Thanks!

After a bit more tinkering (mostly using shorter leads & wires), I’m getting accurate temp readings consistently for a few seconds interspersed with a few seconds of the unusually low readings. For example, the temp input (pin A7) will read 931 for 5-6 seconds, then 765 for 2-3 seconds, then back to 931 for 2-15 seconds, then back to 765 for 2-10 seconds, and so on…

Is this just how it is, and I need to filter out/ignore the obviously incorrect values? Or is there more I can do to troubleshoot?

Not yet @BDub, the core is actually not getting connected to the network, so applying patch

I am reading temperature with a TMP36 sensor, and got some fine and stable readings, except once in a while…

12:38:48 > 976
12:38:49 > 976
12:38:50 > 927 <-----
12:38:51 > 976
12:38:52 > 976
12:38:53 > 976
12:38:54 > 976
12:38:55 > 976
12:38:56 > 976
12:38:57 > 976
12:38:58 > 976
12:38:59 > 935 <-----
12:39:00 > 977
12:39:01 > 977

From the timestamp you can see I read once every second, and they are all very close to each other, except the one I have marked. Right after that single reading that is way off, it goes back to where it was before.

After logging that I tried to search the forum and found this thread about things to do to make it more stable, so I changed from the 3V3 pin to the 3V3* and started the logging again, and here is the result

12:55:28 > 981
12:55:29 > 981
12:55:30 > 981
12:55:31 > 981
12:55:32 > 982
12:55:33 > 982
12:55:34 > 982
12:55:35 > 982
12:55:36 > 982
12:55:37 > 982
12:55:38 > 982
12:55:39 > 640 <-----
12:55:40 > 982
12:55:41 > 982

Again I got some good readings, but still once in a while it is off, this time way off.

I got the sensor connected to A7, a capacitor between the analog input and GND, using the 3V3* pin and reading once every second (can’t bump that up more without starting to affect the project).

What else can I do? It is not like I got some unstable readings, the reading that is off happens around once every 150-200 reading.

@Mikey, you need some super hacker debugging type wizard to help you… I wish I could be everywhere, all of the time o_~ What is happening every 2.5 to 3.3 minutes that could be causing a glitch in your power? This could easily account for this really odd reading. More info about your entire code and setup will help troubleshoot this issue as well.

1 Like

@Mikey Are you using the default Tinker firmware to get these values?

@BDub I noticed (with Tinker) that the further away I am from my wifi access point, the less reliable my temp readings. Meaning that the completely incorrect readings show up more frequently. If I have my Spark Core in the same room as my wifi AP, the incorrect readings are far less frequent.

So I’m guessing that the harder that the wifi chip has to work (whether it be reconnecting or re-sending data), the better chance it has of screwing with analog readings. I’ve also tried the VoodooSpark firmware, and get similar results (although slightly more reliable at longer ranges)