Background polling of a sensor
4Alex
Posts: 119
Hi all,
I am looking for some pointers in how to achieve background polling of a sensor at regular, periodic intervals of time. I want to start small but eventually I'd like to evolve this project into full home automation (and preferably not burn down my house in the process!).
Basically, I have a PC linked to a propeller using RS232 through pcFullDuplexSerial4FC.spin written by Ken Gracey and modified by Tim Moore. On the propeller side, I have a sensor linked through spi (spi.spin) that can be accessed at high bitrate. The propeller runs autonomously and monitors changes in the sensor data. When data is outside a preset range, an alarm is sent to the PC. If the range needs to be adjusted, the PC sends a command to do so. Simple. This is all working at this point but in full 'foreground' approach like with a traditional microcontroller.
I am looking at a way to have the propeller polling the sensor in the background while it still do other internal processing and responding to commands coming from the PC (or sending alarm to it). I guess the multi-cog design is what the propeller is really all about but I have no idea on how to achieve this.
The best would be if someone can point me toward an existing project doing something similar (background polling) so I can learn the ropes. I have searched the obex but with no success.
As always, many thanks in advance for any assistance.
Cheers,
Alex
I am looking for some pointers in how to achieve background polling of a sensor at regular, periodic intervals of time. I want to start small but eventually I'd like to evolve this project into full home automation (and preferably not burn down my house in the process!).
Basically, I have a PC linked to a propeller using RS232 through pcFullDuplexSerial4FC.spin written by Ken Gracey and modified by Tim Moore. On the propeller side, I have a sensor linked through spi (spi.spin) that can be accessed at high bitrate. The propeller runs autonomously and monitors changes in the sensor data. When data is outside a preset range, an alarm is sent to the PC. If the range needs to be adjusted, the PC sends a command to do so. Simple. This is all working at this point but in full 'foreground' approach like with a traditional microcontroller.
I am looking at a way to have the propeller polling the sensor in the background while it still do other internal processing and responding to commands coming from the PC (or sending alarm to it). I guess the multi-cog design is what the propeller is really all about but I have no idea on how to achieve this.
The best would be if someone can point me toward an existing project doing something similar (background polling) so I can learn the ropes. I have searched the obex but with no success.
As always, many thanks in advance for any assistance.
Cheers,
Alex
Comments
The Propeller really doesn't have a "background". It has 8 essentially identical computers (cogs) that have access to the same I/O and memory. It's simply a matter of one computer polling the SPI sensor and leaving information in the shared memory while another computer is talking to a PC and looking at the shared memory information to see if there's something to send to the PC (while another computer is actually doing the serial I/O, bit by bit based on data in a shared buffer).
Mostlikely, you should have one cog doing serial. One cog doing spi, and one interpreting the data from the PC and interpreting data from the sensor. All that's left to do is then add more cogs for more sensors to interface with them.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
Ken Gracey
Parallax, Inc.
·
I stand corrected! My sincere apologies to Chip. You might be 'wired differently' but you certainly both rock!
Cheers,
Alex
This is something that a prop is great for. I have been working on a robot where I have on thread (or cog) update the position of servos incrementally and another thread poll a Ping sensor. Both updates can go on in the background and the main processing loop doesn't have to wait for them.
When I start the ping I set the timing interval. The ping is read at that interval and the result goes into a ring buffer along with the servo position. So I can take a bunch of readings and then average them for more reliability. Or I can pan the head servo and see if any of the readings are dangerously close. Finally I sometimes use array of ping results and servo position to make a little obstacle plot on a TV screen. I am just learning, its amazing what I think I can do.
Enclosed is "Ping Minder" the part that monitors a Parallax ping sensor. It uses This isn't the greatest code, but perhaps it will help you. Let me know if I can help.
Thank you so much for the code! It looks like a very good start for what I am trying to do. I will study your code and adapt it to my sensor. More to come later on...
Many thanks again.
Cheers,
Alex