Hi,
I’m currently doing a project, which requires me to measure and plot (via cosm) temperature and light intensity.
I’m using an LM35CZ sensor for reading the temperature and a Photoresistor for reading the light intensity.
I believe all is good on the hardware side of things - everything should be wired OK.
Since the LM35CZ requires a supply voltage of 4V+, I had to power it directly from Vcc (5V) instead of the 3V3 from the board. I also connected the Vcc GND and the voltage regulator’s GND since it turned out that they weren’t connected - I’m using the SparkFun Imp breakout board, based on the April design.
Attaching a photo - I don’t know if you’ll be able to make everything out…
I’ve got the plotting side of the project going OK (as well as sending out emails via agents :). I can lend a hand if anyone’s having issues with getting either of those things going.
What’s really bugging me is that everything seems to work great one minute, but then the values go haywire for no apparent reason. For example, once the Photoresistor starts reading values close to 0, the Temp sensor starts reading insanely high values…
Is there any known issue with consecutively reading several analog inputs?
I even placed imp.sleep(0.1) after each of the measurements in order to minimize any kind of potential interference between the two ports. Before I put this in I was getting even stranger values from hardware.pinx.read().
I’ll paste a couple of the relative functions just in case:
function checkPRes() { local rawValue = hardware.pin1.read(); local pResValue = 1 - (rawValue / 65535.0); imp.sleep(0.1); return pResValue; }
function checkTemp() { local rawValue = hardware.pin2.read(); local gain = 3.3/65535; local tempVolts = rawValue*gain; local tempActual = tempVolts / 0.01; local tempActualRound = format("%.2f",tempActual); tempActualRound = tempActualRound.tofloat(); imp.sleep(0.1); return tempActualRound; }
(The format() and tofloat() bits in the checkTemp() function are a workaround to set the decimal places since I wasn’t able to find a math.round() or similar function in the Squirrel manual… Please, correct me if there’s an easier / better way to do this, even though it seems to work OK and I don’t think it’s the source of the problem)
And help would be greatly appreciated since I think I’m going crazy!