Thursday, July 12, 2012

Putting Everything Together: Part 4: Random Progress + Optical Dust Sensor Code

Before I start, I just want to mention that I figured out that the BMP Pressure sensor needs have the SCL wire attached to the SCL pin on the Arduino Mega/ADK, and the SDA wire attached to the SDA pin. I guess they were pins 5 and 4 on the Duemilanove, but the Mega/ADK have specifically labeled their pins 20-21 with the SCL/SDA labels. Yes, now it seems trivial, but when the code/examples only told you to "put these wires into pins 4 and 5", it sometimes is a bit hard to figure out everything when so many things can go wrong.

So, now the BMP Pressure Sensor works on the ADK and Mega just like it did on the Duemilanove. :D


Anyways, on Wednesday I also wrote code for running a bunch of sensors together simultaneously, much like what I did for the gas sensors. The sensors include the BMP Pressure Sensor, Temperature/Humidity Sensor, and the Geiger Counter.

Below is a picture of the setup:



Notice that I also wired in the optical dust sensor, which I worked on today.


Optical Dust Sensor

The optical dust sensor works pretty interestingly. The physical setup, for reference, looks like this. The code for it requires that an LED inside the sensor turns on and off during a 10ms cycle:

-Turn on LED for 280µs
-Take reading
-Wait 40µs
-Turn off for 9680µs

So the maximum sampling rate is 1sample/10ms. The original code was simple enough; however, turning this into a library is proving surprisingly difficult, and at the end of the day, I'm still not done. 


This is when I learned about time limits. A microsecond is a really, really short amount of time. Short enough, in fact, that the time it takes to transmit data is significant. Though we are not sure, it seems that the sensor might not be able to read data in time when the code becomes more complicated (and hence takes longer to run through). 

The original way I tried to convert the .ino file into a .cpp library was to use the modulus operator % to get the "stage" of the cycle time, and then determine what to do based on the stage. I've also tried running while loops with the code, but so far, I can't get a reading. Guess I'll keep trying tomorrow. 

No comments:

Post a Comment