Arduino uno for lan of things sketch

For stand-alone microprocessors

Arduino uno for lan of things sketch

Postby Doug Coulter » Sat Mar 14, 2015 9:10 pm

I just finished this (I hope, you know how it is). This is the code for the arduino uno slave to a pi for my "lan of things" over in the next building. It connects to 3 DHT-22 temp/humid sensors, one thermocouple breakout, two counters (water flow in and out), will drive two fets for water valves, and does water level detection in my cistern. I tried to comment the code as to how to hook things up and how to interpret them. I did a comm protocol that is super-simple and allows for multiple uno's (or whatever async serial) devices out there.
First character is the unit ID, which is hardcoded in the unit - I don't need hotplug etc.
Second is command. The protocol is "speak only when spoken to" so wired-or on the lines works out.
For example, to get a report out of unit 1 (this one) you say: 1r<lf>
It will then dump all the current readings. If it takes too long going either way, everyone times out and goes back to state zero - you just try again.
The commands are:
1a (send ack<lf> to the host
1l (led on)
1o (led off)
1r (report)
1i (let water in)
1d (dump water)
1c (close all valves)
! (reset)

And that's all. All commands and responses end with <lf> or <cr><lf> - the code ignores <cr>.
This allows some pretty simple perl on the pi, using its hardware uart and a driver that drives all the uno's you can want (even can power them up it's so strong, which is actually dangerous).
Unos use a 2 transistor buffer with open collector and a pullup to go back to the host, in this case a pi.

Here's the uno side of things:
ArdT1.tar.bz2
The uno sketch
(5.3 KiB) Downloaded 312 times


And here's some simple pi perl to look at it all:
ardtest.bz2
For the pi or pc (you'll need the Device::SerialPort module)
(1.05 KiB) Downloaded 300 times


Right now, it just prints out all the numbers - water level, then the two counters, then 3 temp/humidities, one temp from thermocouple, and the state of the two valve driver outputs. This will soon be going into a mySQL database in the pi, from which gnuplot will make plots and put them on a web page so I can see all this data as plots however far back I ask for on the CGI form....finally.

It should look sort of like this:
2015-03-14-220637_1280x800_scrot.png
Screenshot from the pi


You can see that last temperature number go nuts as I held a flame under the thermocouple. That one is intended to monitor a wood stove, so it couldn't be a silicon type sensor.

The eventual systems will be one per building, each with their own webpage, so I can monitor my campus from any building on it - and control some things via CGI's on those web pages. You could call this a dry run for the remote control of the fusor,
Better to make all the mistakes on things that don't matter as much...
.
Posting as just me, not as the forum owner. Everything I say is "in my opinion" and YMMV -- which should go for everyone without saying.
User avatar
Doug Coulter
 
Posts: 3515
Joined: Wed Jul 14, 2010 7:05 pm
Location: Floyd county, VA, USA

Return to Embedded software

Who is online

Users browsing this forum: No registered users and 1 guest