Yay! My article on Arduino and Raspberry Pi is this month’s cover of The MagPi! Read it on Issuu, or download the PDF.
Thanks to Ash and the rest of the team at the magazine.
work as if you live in the early days of a better nation
Yay! My article on Arduino and Raspberry Pi is this month’s cover of The MagPi! Read it on Issuu, or download the PDF.
Thanks to Ash and the rest of the team at the magazine.
Dear Stewart,
I just wanted to thank you for the fantastic article in the MagPi. Articles like this are very inspiring and help us beginners to see the possibilities that exist in the world of the experienced!
I have tried to expand on the code that you kindly published and would like some help if you can spare the time!
1. Closing the programme is very difficult. I have created a button to .destroy()
This successfully kills the Tkinter widget but the terminal window hangs and sometimes causes an issue with the Arduinio. This means I have to remove the Ardion USB and close the terminal window to get it working.
2. I am trying to add a time and date label. I can get it to display once or by following the get_temp code lines I can get the label to update but it sits in the same place as the temp window. Please can you explain why the labels are placed in this place for I cannot see a .pack command for the temp label.
How can I add my timeDate function and display somewhere else in the widget!!!!
I tried adding anchor in the label.config but this seems to have no effect.
Sorry for the additional work but I really want to learn and expand on the already great article you created.
My code below…..
Thanks for getting in touch. To your points:
1) Yes, I find the program doesn’t quit cleanly sometimes. I think it’s the serial iterator thread getting hung up, but I can’t be sure.
2) Your code was trying to put the time label into the temperature label widget. Under the
label.pack(anchor='nw')
code, I added two lines of code to my original program:and I changed the get_temp function to read:
So the function isn’t quite just updating the temperature any more. Clean code? Maybe not. It works, though.
Tk’s pack() geometry manager is weird. For anything more than a couple of widgets, I recommend grid(), which is much more logical.
Hi Stewart,
I have been working quite a bit with PyFirmata for my console-based command program and I also had been experiencing serial-port issues after exiting my PyFirmata programs. I’ve looked over several examples throughout the web and took at peek at the source as well and after reading the comment above, I think I may be able to offer some help on how I cleanly exit a PyFirmata script.
There appears to be another overlooked/undocumented function that seems to ‘cleanly’ destory the board object and restore the serial port.
I use the following line in my except: blocks just in case there is an error while troubleshooting and also before my destroy() calls so the USB port will be left tied up:
board.exit() # properly exit pyfirmata board instance and restore serial port
Hope this helps!
Matt
Thanks, Matt — I’ll certainly try that.