20 hours ago •
For a project at work I recently deployed a few hundred Circuit Python boards that were embedded as one component within a larger system.
As part of planning for this we thought about the question: "What if we find a problem with the python code after the boards are already deployed?" We started looking into ways to update the code on the board. Our system includes an Android device that the Circuit Python board is plugged in to. For a while we assumed USB Storage would work, but once we got around to testing it out we realized that it didn't. As those pesky real-world projects tend to this one came with a tight deadline, so we had to drop it and move on to other things to get that project completed.
Once we got everything shipped out and things slowed down a bit I got to tinkering with the Circuit Python boards a bit more. I played around with the serial connection and REPL a bit and starting thinking maybe this was a better avenue to interact with the board on Android.
The first real world test was USB Terminal program from the Play Store. I loaded it up and was able to see print() outputs from a Circuit Playground Express. Next up was testing the CTRL keys, which is no trivial task on a mobile phone. It turns out there are also keyboards that include CTRL keys on the Play Store so I got one of those installed/enabled/set as my keyboard. Sure enough sending CTRL-D and CTRL-C worked correctly when I sent them via the terminal program using the special keyboard. As the final proof of concept test I used the terminal program to enter the REPL and save hello world to code.py. After a quick detour figuring out the storage mounting it was working perfectly. At this point I knew what I wanted to do was possible I just needed to bring it all together into my own app. The idea gets shelved for a bit here waiting to get pulled out again next time we have a bunch of boards getting shipped out.
Around the holidays though I got to thinking about using this idea for something outside of the work deployment. I was looking for a way to bring Circuit Playground boards with me to family gatherings and show them to the kids and teach them about the board and how to make it do neat things. I could bring a laptop but then I've got to lug that around and get it out plus pack it away after, I didn't want the hassle. I could use a battery pack, but then I can't really show the code or change it to do much different stuff especially things that the person being shown suggests. So the thought is maybe I can use the USB Serial idea from before but make the app into more of a basic IDE that can edit and run code and use the REPL.
I did not quite get it working in time, but there are more holidays right around the corner so I'll be ready for those. Plus I can use my phone to reprogram the Circuit Playground ornament hanging on the Christmas tree.
2 days ago •
Github user [alanjds] opened an issue asking to add a Tab button to the application for use with REPL. I didn't even know that the REPL offered tab completion before that. It was pretty straight forward to add a tab button and right away I could tell that it was possible to make it work because it was able to make suggestions about what I had typed. But to use it effectively was bit more tricky because sometimes it returns full strings and other times it only returns the ending part of the string, and other times it returns lists of available strings, so the app needs to behave correctly in all these cases. In the end I settled on reading the string out of the display text box. It's working pretty well but there are still some scenarios where the behavior is not great.
If you want to give it a try the debug apk in the repo has been updated to the new versions. Let me know how it goes if you do!
12/01/2018 at 17:56 •
The app uses this library for USB serial communication: https://github.com/felHR85/UsbSerial
It comes in synchronous and asynchronous flavors . I've tried both but had better luck with the asynchronous overall so far. The downside is that flow control doesn't seem to be working so we have to have an artificial delay between commands or else sometimes they get spliced together on subsequent writes to the serial port. In the end I need to either work out the synchronous controller, or else figure out how to get flow control working, that would speed up, perhaps considerably, the time it takes to save code back to the board. Another option to explore is writing more than one line at a time. I had trouble with writing the full file at once, but I suspect chunks larger than a single line are possible.