Good morning my thirsty friends!
It's been a long time, well, 10 days, since my last entry. I'm sorry for that, although I really made big progress, there wasn't much thrilling things to tell. I'll do that all in once, today in this post. It's going to be pretty technical and dry, so if you skip this one I'll understand... :)
By browsing on some forums I found a software called
"Mash-it" from a german hobby brewer. (Thank you, Dunkelbrauer!) It's written in Java, and although everybody knows that Java is never the solution ;) and he doesn't use the same hardware as me, I was happy to find that. He implemented a possibility to drive the hardware over command line tools. The software expects a temperature sensor and a heater and you can add a mixer. For the heater and the mixer you've to be able to send on and off commands over command line, and you need a command to make your hardware print their switch state and the temperature to the systems standard output. So far so good, as I was already able to send for example 1on over the arduinos serial monitor to switch on the LED 1 on my arduino, send a 1get and receive a 1 for on or a 0 for off as state of each of the eight outputs and send temp to make the arduino print the current temperature. So I only had to find a program which sends those commands over serial to my arduino and was accessible trough command line, which must be an easy step, I thought.
Well, one can be quite wrong.
After some googling I tried to do that with "screen". Pretty easy, you type screen /dev/cu.usbmodem621 in your terminal and you've a session open where you can send end receive data from the arduino. But theres no way to make a single command send temp and retrieve the data back, which is what I'd need for Mash-it. And even worse, every time you open a screen session, it resets and reboots the arduino which makes all outputs blink uncontrolled for a moment, absolutely not usable. At this moment I was far from knowing that you can cut the connection on the solder pads called reset-en on the arduino to prevent it from resetting on every serial access, I thought it was an issue with screen.
Back to google and arduino.cc I found popen(). But you can't read back data from serial with that neighter, basically the same problem like before. Than came the magic word: POSIX. I really thought: thats it! as I found
"arduino-serial". But long story made short: I didn't get it to work. It sent data and sometimes received something but very very shaky and unreliable. And worst of all it lost the carriage return on its way trough serial, which is elementary for the input parsing I do on the arduino.
Well damn it, I'll work trough POSIX. And thats why it took me 10 days for my next entry here. :)
I first had to see, that my C was still not on a usable level, because I didn't understand anything in the tutorials and howtos for POSIX and serial communication. So, let's do it, once again: "Learn C on a Mac" by Dave Mark. That's where you want to start your programming career. So after a whole day spent in learning C again, shit became serious. I started writing my own little C serial program, called "mylittleserial.c". If somebody's interested to get it just say. Step by step I worked my way trough all that stuff. Opening a serial port and write to it is relatively easy, although you wont believe how many damn parameters you can (and must) set. I became almost crazy with that old prehistorical modem initialization stuff... But reading data back from the serial port is a whole oder story. You really have to read byte after byte and time and parse that shit correctly or you'll get unpredictable results. You can't imagine how long I tinkered around until I found out that I need to wait two seconds after booting the arduino before I can talk with him. And as it became slowly stable, I encountered the problem that after a temp command it didn't accept anything else and I had to reset it. Imagine, you can turn on and off every LED ten times in a row like a charm, but ask once for the temperature and you're done. And all that because of a f€@&ing = instead of a >. But then,
tuesday evening the breakthrough. Mash-it has a manual hardware control build in and it worked! It turned my LEDs on and off and read the temperature!
That definitively made one future beer brewer happy! :)
Last thing I had to fix was the hard coded port. I had to enter the usb port on which the arduino hung manually in the source code before compiling and I didn't want to give it as a parameter on every program run so the program needs to find the arduino by himself. I do that by searching /dev for cu.usbmodem and after some hacking around it now works perfectly.
Here's a picture of the hardware simulation of mash-it running my arduino.
Sorry again for the boring post, but maybe there's people out there which encounters the same problems as me and now they know where to get help. And I'm confident that the next post will rock more... :)
Cya buddies, thx for the attention!