Monthly Archives: August 2021

pyboards are beautiful!

They arrived, and they work on BIPES “as they are”. Just connect pyboard to the USB port and use it with BIPES!

Console, just after connecting:

First test program:

Test program running:

BIPES File manager (fully web based, with upload, download, edit, run and delete options over USB/Serial, replacing ampy):

Program:

https://bipes.net.br/beta2/ui/#f4uscm

Soon: custom blocks for the pyboard and pyboard option!

Doing Research in Brazil

When we love what we do and have no responsibility with our own money 😦

Boards purchased for research / experiments:

2 pyboards from MicroPython Store (They are great, by the way)

Total = 64.75 GBP

Shipping: 45 GBP

Total order with shipping: 109.75 GBP (=149.56 USD or =809.91 BRL [R$])

Taxes: 850 BRL – more than the value of the products plus the shipping!

Total: R$ 1659 (BRL) for 2 pyboards!

R$ 1659 would buy:

  • 24 Arduinos UNO
  • 70 Big Macs @ Brazil (Big Mac Index)
  • 7 PyBoards v1.1 (without considering shipping)
  • 6 PyBoards v1.1 (considering shipping)

(*) GBP/Dollar conversion on 19-08-2021

The order:

The taxes:

And the R&D investment compared to the judiciary system on several countries:

It still works!

Nostalgia: My TK 3000 iie Compact, a brazilian microcomputer, still works nicely!

It is an Apple II clone with 65C02 CPU, 128Kb of RAM and green screen! From 1987!

Snek Lang: feels like Python on Arduinos

Snake image credit: Snek project (https://sneklang.org/)

There’s a long time I’ve been interested on some interpreter similar to Python that could run on low end Arduino boards, such as Arduino Nano, Uno or Mega. I have tried “python-on-a-chip” (https://code.google.com/archive/p/python-on-a-chip/) / PyMite (https://github.com/dwhall/p14p) and TinyPy (https://github.com/philhassey/tinypy). Some of these projects are quite old and none of them had the characteristics I wanted. Moreover, seems that they are not maintained anymore. I also tested Arduino-PyMite (https://github.com/netpipe/Arduino-Pymite), a version of PyMite that can be easily built and loaded on Arduino using Arduino IDE, but it is also not what I wanted.

But today I found a recent project by accident: Snek: A Python-inspired Language for Embedded Devices (https://sneklang.org/). Created by Keith Packard, at the end of 2019, snek has a syntax similar to Python and implements a subset of Python language. I got impressed on how the tools are well organized and structured and about the robustness of the language running tests on an Arduino Mega and an Arduino Uno (https://keithp.com/blogs/snek-duino/).

But what I loved most, is the interactive REPL over serial port using standard terminals. Just flash snek on an Arduino, open your terminal and “talk” to the board as you would on a Python REPL prompt. This is so much clean and practical!

Another great work of Keith was to provide tools to easily install / flash snek on Arduinos and other boards. There are also Ubuntu packages for snek, and even a PC interpreter to play with snek on a desktop computer.

In my case, I downloaded and installed the Linux version with these commands:

$ wget https://sneklang.org/dist/snek-linux-1.5.sh
$ chmod +x snek-linux-1.5.sh
$ ./snek-linux-1.5.sh

I installed snek on ~/Snek. After that, we can use tools to easily flash snek on our Arduinos! For example, to flash snek on an Arduino Mega, simply run:

$ cd Snek
$ ./snek-mega-install

Done! Now we can already access snek prompt with any serial terminal. In my case, I tried with minicom:

minicom  -b 38400 -D /dev/ttyACM0

Note that some snek versions are configured to 115200 bps and other, as I have seen on the source code are configured for 38400. The package mentioned above are set to 38400 for Arduino Mega and Uno. Anyway, I could then easily use the REPL to control a LED and read the Arduino’s ADC:

Blinking the LED on D13 pin:

Code:

> talkto(D13)
> while True:
+  on()
+  time.sleep(1)
+  off()
+  time.sleep(1)

Reading the ADC:

Snek input values range from 0 to 1 on the ADC, so 1 means 5V for the standard ADC and 0 means 0V. If we multiply the reading by 5.0, we will have the ADC reading in volts. Quick and easy!

Code:

> while True:
+  print(read(A0)*5.0)
+  time.sleep(0.8)

Detailed documentation and functions:

https://sneklang.org/doc/snek.html

Snek’s author/creator presenting it:

https://www.youtube.com/watch?v=EWMFNqkgt1o&t=2323s

Sources:

https://github.com/keith-packard/snek

Snek has also an editor written in Python, called snekde, but I am happy with the simple serial console. One interesting possibility is to create a web page using avrbro (https://github.com/kaelhem/avrbro) and Web Serial, allowing new users to flash snek on Arduinos directly from a standard web page!

Finally, I decided to implement some snek functions as BIPES blocks! Yes! BIPES meets Arduino thanks to Snek! And it worked nicely! Now we can use BIPES to program Arduino with Snek using blocks!

https://bipes.net.br/beta2/ui/

Here is a complete BIPS program, with 3 functions, generating and running code for Snek!

And a simpler example running:

Result:

My thanks and congratulations to Keith Packard for this great project! I also thank Jorge Marques (https://github.com/JorgeGMarques | https://www.linkedin.com/in/gastmaier/ ) very much for the refactoring he has made on BIPES code, making it easier to add Arduino / Snek target boards with specific parameters, such as serial speed and buffer size configured at BIPES devinfo.json (https://github.com/rafaelaroca/BIPES_ui_testing).