1. Raspberry Pi temperature sensors
- Posted by ryanj Jul 25, 2021
- 1566 views
I wrote a program for the Raspberry Pi that successfully reads DS18B20 temperature sensors! It is a common IC that uses 1-wire protocol, connected to one of the GPIO pins. It turns out it's already supported by the OS, so it just took some system_exec() and pipeio:exec() calls, reading special files, and some sequence manipulation. It was surprisingly easy! I'm using "euphoria-4.1.0-ARMv6-hardfloat" without any issues so far.
It will be handy for monitoring temperature in multiple locations around the house. It reads the sensors every 1 minute and logs the data in a format easy for other programs to read. I plan to add other types of sensors (humidity, gas, light level, etc.)
It's not quite finished yet. I plan to release it to the public soon, with documentation.
https://tutorials-raspberrypi.com/raspberry-pi-temperature-sensor-1wire-ds18b20/
2. Re: Raspberry Pi temperature sensors
- Posted by katsmeow Jul 26, 2021
- 1526 views
I wrote a program for the Raspberry Pi
Wow, i just counted 22 versions of the Raspi on wikipedia. The low end seems to compete with the olde BASIC Stamp, and the priciest seems to compete with the generic mini-itx (plus GPIO pins, minus pci).
The Raspi 3 runs an open source NASA Rover : https://github.com/nasa-jpl/open-source-rover
Or maybe it's a lawn mower. A pinecone picker upper. A tiny garden tractor. A deer watcher.
Either way, Ryan is connecting OE to the real world, the computer can finally know by sunlight if it's 1am or 1pm. Or raining. Or know the water pump is running, but the water isn't moving. Or which chair i am sitting in. Or if the front door is locked, window closed, lights off, and which way the wind is blowing. Or if the car is warmed up or cooled off. Maybe no limit with Phix/OE code on the Raspi.
Kat
3. Re: Raspberry Pi temperature sensors
- Posted by Spock Jul 26, 2021
- 1498 views
I wrote a program for the Raspberry Pi
Wow, i just counted 22 versions of the Raspi on wikipedia. The low end seems to compete with the olde BASIC Stamp, and the priciest seems to compete with the generic mini-itx (plus GPIO pins, minus pci).
The Raspi 3 runs an open source NASA Rover : https://github.com/nasa-jpl/open-source-rover
Or maybe it's a lawn mower. A pinecone picker upper. A tiny garden tractor. A deer watcher.
Either way, Ryan is connecting OE to the real world, the computer can finally know by sunlight if it's 1am or 1pm. Or raining. Or know the water pump is running, but the water isn't moving. Or which chair i am sitting in. Or if the front door is locked, window closed, lights off, and which way the wind is blowing. Or if the car is warmed up or cooled off. Maybe no limit with Phix/OE code on the Raspi.
Kat
This would be my preferred platform for some (physically) portable custom smartware. One application I'd like to have is a water level indicator for farm water tanks scattered about. Just some blinky LEDs for output will do.
Spock
4. Re: Raspberry Pi temperature sensors
- Posted by ghaberek (admin) Jul 27, 2021
- 1458 views
so it just took some system_exec() and pipeio:exec() calls
I'm not too keen on saying "I did this with Euphoria" only to say "by using system(), etc." it just feels a bit dishonest. Anybody can run another app that does the heavy lifting.
I don't have a sensor handy to test this right now, but you should be able to copy the Bash script near verbatim:
#!/usr/bin/env eui include std/io.e include std/convert.e -- Read Temperature object tempread = read_file( "/sys/bus/w1/devices/10-000802b4ba0e/w1_slave" ) -- Format atom temp = to_number( tempread[match("t=",tempread)+2..$] ) / 1000 -- Output printf( STDOUT, "The measured temperature is %0.2f°C\n", temp )
Of course, this could do with some better error and type checking, as could the example Bash script.
-Greg
5. Re: Raspberry Pi temperature sensors
- Posted by irv Jul 27, 2021
- 1459 views
It's very easy to monitor things (like farm tanks) by creating web pages. That way you can view one or more sensors using your phone or computer. As long as they're in range of a wifi signal.
You can do this with one of the raspberry pi models, or with esp8266 (much cheaper and lower power, so more suitable for a solar powered setup).
Difference, other than price, is the Raspberry Pi is a full-fledged computer, so you can write your programs in Euphoria, rather than C. You can also log in via VNC, and have full access to the Raspberry Pi.
Cautions: inputs for these are 0-3.3 volts. Hooking up sensors which commonly have a 0-5 volt output can fry the pie. Esp analog input is 0-1 volt. Same warning. Optical isolated level changers are available for a couple of bucks.
6. Re: Raspberry Pi temperature sensors
- Posted by katsmeow Jul 27, 2021
- 1430 views
I looked at the ESP stuff years ago, and data was not forthcoming, and questions were never answered. On the face of it, the modules look to be wifi interfaces, with no data on how they are to be connected to anything. There's many such Chinese modules, and the web is littered with feedback of them not working as advertised. When people ask for something and get no answers for years, eventually they give up. I gave up. Near as i could tell, OE and Eu were never going to know the position of a toggle switch, let alone control an automated process. And that is disgusting to me, considering the C64 was, for a time, operating the people mover at Hartsfield International Airport, and i patched one into a gigantic Modicon-controlled injection molding machine in 1984. The C64 also made a nice lil HPIB/IEEE-488 controller for Hewlett-Packard and Tektronix equipment. So i may not know modern Chinese stuff because no one answers my questions, but freaking been there done that before they were born.
Making a simple webpage to watch the water tank isn't the same as having smarts out there to handle the gotchas such as the pump running dry for hours, destroying the shaft seal. Or the engine starter motor staying engaged to the flywheel. Or belts coming off at 2am.
The pi can also save events to hdd, so even on a slow connection you can see how that goat got into the cattle trough overnight. I have some hdd that aren't much bigger than the Pi3 in it's plastic case.
The pi can also shut down and wake up periodically, by timer or responce to stimuli, to save power. To me, being smart for the duration of an event beats being stupid all the time.
Rather than giving half-answers from Wikipedia like "use a ESP-xx module" (but not HOW), Ryan is providing a seamless remote many-input many-protocol solution, with a seamless interface using ethernet, wifi, zigbee, 1-wire, 2-wire, I2C, SPI, and an 8-bit parallel. You can write the code on the desktop, upload it to the remote, and run it there. There's many benefits besides "you can write your programs in Euphoria, rather than C", starting with the entire data gathering, distribution, and munging is written in Euphoria (or Phix). Unless you count calling into the OS's API as "dishonest".
Re 3.3v vs 5v, various real-world situations were discussed. Basically, nothing from the user is plugged into the raspi, it all goes thru a card with protective measures. It's not economical to blow up the pi while trying to get an undocumented Chinese module to work with it.
And there's nothing saying the raspi cannot be the gateway to remote zero-power dumb terminals.
Kat
7. Re: Raspberry Pi temperature sensors
- Posted by katsmeow Jul 27, 2021
- 1441 views
so it just took some system_exec() and pipeio:exec() calls
I'm not too keen on saying "I did this with Euphoria" only to say "by using system(), etc." it just feels a bit dishonest. Anybody can run another app that does the heavy lifting.
Yea, how dishonest is it to have a bat file like this rather than use the idiot taskmanager gui.....
taskkill /IM firefox.exe /F
Heck i even named it "Kill FireFox.bat". Just my opinion, but using a bat on unresponsive programs seems to be poetically appropriate.
Kat
8. Re: Raspberry Pi temperature sensors
- Posted by ghaberek (admin) Jul 29, 2021
- 1383 views
I'm not too keen on saying "I did this with Euphoria" only to say "by using system(), etc." it just feels a bit dishonest. Anybody can run another app that does the heavy lifting.
Yea, how dishonest is it to have a bat file like this rather than use the idiot taskmanager gui.....
taskkill /IM firefox.exe /F
Heck i even named it "Kill FireFox.bat". Just my opinion, but using a bat on unresponsive programs seems to be poetically appropriate.
Wow that's an impressive jump, Kat. You went from "using system() feels dishonest" to "batch files are bad and Kat is dumb for using them" in one beat, huh? Have you ever heard the phrase, "not even wrong?"
-Greg
9. Re: Raspberry Pi temperature sensors
- Posted by katsmeow Jul 29, 2021
- 1353 views
I'm not too keen on saying "I did this with Euphoria" only to say "by using system(), etc." it just feels a bit dishonest. Anybody can run another app that does the heavy lifting.
Yea, how dishonest is it to have a bat file like this rather than use the idiot taskmanager gui.....
taskkill /IM firefox.exe /F
Heck i even named it "Kill FireFox.bat". Just my opinion, but using a bat on unresponsive programs seems to be poetically appropriate.
Wow that's an impressive jump, Kat. You went from "using system() feels dishonest" to "batch files are bad and Kat is dumb for using them" in one beat, huh? Have you ever heard the phrase, "not even wrong?"
-Greg
Please say where i said anything like "batch files are bad and Kat is dumb for using them".
I have heard of the phrase. I have not said anything which cannot be proven wrong or right.
I use a system specific file type, the .bat (batch) file, to call another system specific program (taskkill) to accomplish something OE cannot do. I don't feel dumb or dishonest about it at all, even tho it is a system call. I am trying to find what it is you are saying is dishonest. If i put the bat file, which i wrote, into an OE folder, and called the bat file with an OE program (which i write) using exec(), is it now dishonest?
Kat
10. Re: Raspberry Pi temperature sensors
- Posted by ghaberek (admin) Jul 30, 2021
- 1321 views
I use a system specific file type, the .bat (batch) file, to call another system specific program (taskkill) to accomplish something OE cannot do.
And there's the rub. Nothing wrong with using a batch file to do batch file things. But Euphoria can absolutely enumerate and terminate processes using the Windows API. This is the Way.
-Greg
11. Re: Raspberry Pi temperature sensors
- Posted by katsmeow Jul 30, 2021
- 1312 views
I use a system specific file type, the .bat (batch) file, to call another system specific program (taskkill) to accomplish something OE cannot do.
And there's the rub. Nothing wrong with using a batch file to do batch file things. But Euphoria can absolutely enumerate and terminate processes using the Windows API. This is the Way.
-Greg
Ok, but Ryan used system_exec() and pipeio:exec() to perform the action vs calling a windows API directly. Those two exec() functions are in OE to do exactly what he used them to do. I don't see your moral objection to that. Heck, i use puts() so i don't need to call API to open a fake dos console box to print() to. Without the OS's API calls available, however you call them, i don't see how OE can do what Ryan needed doing.
Years ago i wrote an Euphoria v3.1 program that used a web interface to translate between human languages. I didn't write the translator. What i did do was loop the process, to translate between languages not available on the website. And Ryan is doing something else you didn't do.
Kat
12. Re: Raspberry Pi temperature sensors
- Posted by ChrisB (moderator) Aug 02, 2021
- 1184 views
SO what you're actually saying Kat, is that there really is more than one way to skin a cat! Totally agree, a job done, is a job done.
Cheers
Chris
13. Re: Raspberry Pi temperature sensors
- Posted by jimcbrown (admin) Aug 04, 2021
- 1137 views
SO what you're actually saying Kat, is that there really is more than one way to skin a cat! Totally agree, a job done, is a job done.
Agree 100% with this sentiment.
to accomplish something OE cannot do.
But Euphoria can absolutely
Ok, but Ryan used system_exec() and pipeio:exec() to perform the action vs calling a windows API directly.
Yeah, using a windoze API wouldn't make sense here, considering that most Pi's that I've seen run some flavor of nix.
Those two exec() functions are in OE to do exactly what he used them to do.
Yep, that's what they're there for.
Without the OS's API calls available, however you call them, i don't see how OE can do what Ryan needed doing.
Me either.
I don't see your moral objection to that.
Although Greg used the term "dishonest", my 2 cents is that the object is one of accuracy rather than on a moral basis. It's true that Ryan "did this with Euphoria" but he also used other languages, such as Bash scripts, when an Euphorian alternative was available.
Greg clarifies,
Nothing wrong with using a batch file to do batch file things.
I take this to mean that from Greg's POV, there's nothing wrong with Ryan using the bash script in is project as-is, but it's inaccurate to say that it's done with Euphoria (I guess with a silent implication that it's using as much Euphoria as possible) because of the reliance of the bash scripting language (when doing so is not strictly necessary) but instead of calling anyone a liar, Greg simply finds a way to make the statement honest by writing some Euphoria code.
Using the OS API would be an exception because - unless one is working with the bare hardware - there's no way to do some things without invoking the OS's API. So that doesn't break the "Use Euphoria as much as possible to do things and as little of other languages as possible." principle.
Years ago i wrote an Euphoria v3.1 program that used a web interface to translate between human languages.
Me too. But with an older version of Eu, 2.2 or 2.3 iirc.
I didn't write the translator.
Me either.
What i did do was loop the process, to translate between languages not available on the website.
Very cool. That's something I hadn't accomplished with my version.
And Ryan is doing something else you didn't do.
Well, to Greg's credit, he did provide the Euphorian version of the bash script that Ryan was using. Greg isn't doing what Ryan did, but he did spent some time and energy to help Ryan make his project powered even more by Euphoria.
Perhaps Ryan thought that what the bash script did was something that Euphoria couldn't do, but Greg demonstrated otherwise. Seems like a win all around to me.
14. Re: Raspberry Pi temperature sensors
- Posted by ryanj Aug 06, 2021
- 1043 views
It's hard to reply to every comment, so i'll just summarize my thoughts.
There's nothing wrong with using shell scripts, especially on linux, where you can do almost anything at the command line. But, writing a euphoria program to do system calls to run the same commands is useful, because you can feed the output string into a sequence and do stuff with it in a euphoria way. I actually use a bash script to start a euphoria program to do system calls, with pipes to get the results. It works great.
Status update: I have a program on the Raspberry Pi that starts automatically on boot (a cron job) which sets up the 1-wire protocol on one of the GPIO pins, then runs continuously to read the temperature sensors and write the results to a log file in JSON format every 1 minute. Everything is on a shared folder (using Samba), so, i have a program running on my Windows desktop using redylib that reads the log files on the shared folder and displays status with a GUI. It's working great so far, but it still needs some polishing.