Category Archives: Uncategorized

Blockly User Summit Hands-On

Boards in order of appearance and connection port (from left to right):

[Board 1 (8061); Board 3 (8063); Board 4 (8064); Board 5 (8065); Board 2 (8062)]

Live camera:

http://uc.bipes.net.br:8280/cgi-bin/mjpg/video.cgi?subtype=1

User: camera / Password: camera123

ESP8266 boards for remote tinkering with BIPES / Blockly

Five boards are available – one user at a time!

Board 1: ws://uc.bipes.net.br:8061 / Pass: bipes1

Board 2: ws://uc.bipes.net.br:8062 / Pass: bipes10

Board 3: ws://uc.bipes.net.br:8063 / Pass: bipes0003

Board 4: ws://uc.bipes.net.br:8064 / Pass: bipes04

Board 5: ws://uc.bipes.net.br:8065 / Pass: bipesFive

Program 1 – Write B to LED Matrix

http://bipes.net.br/ide/#noyrty

Open the URL above and connect to the board:

Program: L and O

http://bipes.net.br/ide/#xw59kk

Program: C

http://bipes.net.br/ide/#dsqdmm

Program: K

http://bipes.net.br/ide/#tzgf9f

Program – L and Y

http://bipes.net.br/ide/#6pkjiw

IoT Demo:

https://bipes.net.br/ide/#fgjyum

Access the link above and check the IOT and EasyMQTT tabs.

You can also view only the data (without the program):

http://bipes.net.br/freeboard#fgjyum

OR read the QR-Code on your phone:

BIPES Talk @ Blockly User Summit

Hello!

Tomorrow, we will have the honor to present BIPES Project at the Blockly User Summit (link below). BIPES is a unique open-source platform, that allows users to quickly create embedded and IoT solutions using visual block-based programming. BIPES is currently in use in more than 100 countries by more than 10.000 recurrent users!

http://bipes.net.br/ide/

https://developers.google.com/blockly

https://sites.google.com/view/blockly-user-summit-2022/agenda

Serial GUI with BIPES

Arduino, ESP32, ESP8266, Raspberry Pi, etc: we always need a quick and simple interface (GUI) to view data and send data to microcontroller boards. With a little help from Jorge Marques (https://github.com/gastmaier) now we can push strings to be sent to the Serial port. These strings can be prepared/customized on any HTML freeboard widget on BIPES IoT tab. Note that we can use this to send pre-defined serial messages to any serial device! Of course, as already done many times, you can also receive data and route it to the freeboard using BIPES data source, allowing serial data to be seen on any freeboard widget.

Direct link to the project:

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

To use it, create a new pane and add a HTML widget to the IOT tab with freeboard:

Then, click on JS Editor and paste the code for each widget:

You can type/build any user interface using HTML. It will be automatically saved and you can share with anyone when you share the BIPES project by URL. The important part is:

parent.bufferPush(cmd);

The parent.bufferPush(cmd); command will send a message from your Javascript/HTML GUI to the serial device connected to BIPES console on the web browser. There are some examples below, but you can build your own user interfaces!

Code for the slider:

<style>
.slidecontainer {
  width: 100%;
}

.slider {
  -webkit-appearance: none;
  width: 100%;
  height: 25px;
  background: #d3d3d3;
  outline: none;
  opacity: 0.7;
  -webkit-transition: .2s;
  transition: opacity .2s;
}

.slider:hover {
  opacity: 1;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 25px;
  height: 25px;
  background: #04AA6D;
  cursor: pointer;
}

.slider::-moz-range-thumb {
  width: 25px;
  height: 25px;
  background: #04AA6D;
  cursor: pointer;
}
</style>
</head>
<body>

<h1>Slider test</h1>
<p>BIPES and Freeboard</p>
<p>Send value to serial console</p>
<p>from freeboard!</p>

<div class="slidecontainer">
  <input type="range" min="1" max="65000" value="50" class="slider" id="myRange">
  <p>Value: <span id="demo2"></span></p>
</div>

<script>
var slider = document.getElementById("myRange");
var output = document.getElementById("demo2");
output.innerHTML = slider.value;

slider.oninput = function() {
  output.innerHTML = this.value;
  var cmd='pwm25.duty_u16(' + this.value + ')' + String.fromCharCode(10) + String.fromCharCode(13);
  console.log('cmd='+cmd);
  parent.bufferPush(cmd);  
}
</script>

Code for the buttons:

<h1>Button Test</h1>
<p>Send value to serial console
from freeboard!</p>

<center>
<br>
<button onclick="ligar()">LED On</button>
<br>
<br>
<button onclick="desligar()">LED Off</button>
<br>
<br>
<button onclick="pwm()">PWM Mode</button>

<p id="demo"></p>

<script>
function ligar() {    
      var cmd='gpio_set(25, True)' + String.fromCharCode(10) + String.fromCharCode(13);
      console.log('cmd='+cmd);
      parent.bufferPush(cmd);
}

function desligar() {    
      var cmd='gpio_set(25, False)' + String.fromCharCode(10) + String.fromCharCode(13);
      console.log('cmd='+cmd);
      parent.bufferPush(cmd);
}

function pwm() {    
      var cmd='pwm25 = PWM(Pin(25))' + String.fromCharCode(10) + String.fromCharCode(13);
      parent.bufferPush(cmd);
      var cmd='pwm25.freq(1000)' + String.fromCharCode(10) + String.fromCharCode(13);
      parent.bufferPush(cmd);    
}
</script>

RP2040 operating temperature

Yesterday we described the usage of Ethernet with RP2040 (Raspberry Pi Pico) using the W5100s-EVB-Pico board here:

As I started working today, I decided to let it connected to the power source to monitor its operation and robustness.

Here is a plot of the first minutes of operation using BIPES EasyMQTT:

After that, the temperature is stable at about 41 degrees Celsius:

The data is updated in real-time and open for anyone at the link (EasyMQTT tab):

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

Building MicroPython for the Raspberry Pi PICO with Ethernet and WebREPL support

WizNet is offering a low-cost Raspberry Pi PICO with Ethernet: the W5100S-EVB-Pico at about 9 dollars worldwide. For example, it can be purchased at Digikey here. There are firmwares ready to download and use based on MicroPython and CircuitPython. I used this one and it worked fine:

https://github.com/Wiznet/RP2040-HAT-MicroPython

However, some features I really wanted and needed were not available on this build. So let’s build ours.

Quick solution

This post discusses several issues and steps to compile and use Ethernet for Raspberry Pi Pico. For a ready-to-use quick solution, just go to:

Compiling MicroPython

Building MicroPython for the Raspberry Pi Pico is very easy and well documented. The best resource and guide I found is the official documentation from the Raspberry Pi Foundation using the document Raspberry Pi Pico Python SDK:

As explained in the above document, the commands to build Raspberry Pi Pico are:

mkdir pico
cd pico
git clone -b master https://github.com/micropython/micropython.git
cd micropython
git submodule update --init -- lib/pico-sdk lib/tinyusb
sudo apt update
sudo apt install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential
make -C mpy-cross
cd ports/rp2
make

After the build is done, the firmware built (firmware.uf2) will be available at the directory build-PICO.

Now we can install picotool to check the modules included as builtins in the firmware. picotool install is explained here:

mkdir pico
cd pico 
git clone -b master https://github.com/raspberrypi/pico-sdk.git
git clone -b master https://github.com/raspberrypi/picotool.git
cd picotool
sudo apt-get install libusb-1.0-0-dev
mkdir build
cd build
export PICO_SDK_PATH=~/pico/pico-sdk
cmake ../
make

Before running cmake ../, edit CMakeFiles.txt and add:

install(TARGETS picotool RUNTIME DESTINATION bin)

install(TARGETS picotool RUNTIME DESTINATION bin)

This solved a compilation bug for me, as reported here.

Now we can use picotool with the built firmware:

./picotool info /home/rafael/builds/pico/micropython/ports/rp2/build-PICO/firmware.uf2 
File /home/rafael/builds/pico/micropython/ports/rp2/build-PICO/firmware.uf2:

Program Information
 name:            MicroPython
 version:         v1.18-128-g2ea21abae
 features:        USB REPL
                  thread support
 frozen modules:  rp2, _boot, ds18x20, onewire, dht, uasyncio, uasyncio/core,
                  uasyncio/event, uasyncio/funcs, uasyncio/lock,
                  uasyncio/stream, neopixel

This default configuration lacks some important modules. MicroPython allows us to add other modules by editing the manifest file:

File vi rp2/boards/manifest.py original contents is:

freeze("$(PORT_DIR)/modules")
freeze("$(MPY_DIR)/drivers/onewire")
freeze("$(MPY_DIR)/drivers/dht", "dht.py")
include("$(MPY_DIR)/extmod/uasyncio/manifest.py")
include("$(MPY_DIR)/drivers/neopixel/manifest.py")

We have to edit it and add some lines, so manifest.py will have these contents:

freeze("$(PORT_DIR)/modules")
freeze("$(MPY_DIR)/drivers/onewire")
freeze("$(MPY_DIR)/drivers/dht", "dht.py")
include("$(MPY_DIR)/extmod/uasyncio/manifest.py")
include("$(MPY_DIR)/drivers/neopixel/manifest.py")

freeze("$(MPY_DIR)/tools", ("upip.py", "upip_utarfile.py"))
freeze("$(MPY_DIR)/drivers/display", "ssd1306.py")
include("$(MPY_DIR)/extmod/webrepl/manifest.py")

# Libraries from micropython-lib, include only if the library directory exists
if os.path.isdir(convert_path("$(MPY_LIB_DIR)")):
    # file utilities
    freeze("$(MPY_LIB_DIR)/micropython/upysh", "upysh.py")

    # requests
    freeze("$(MPY_LIB_DIR)/python-ecosys/urequests", "urequests.py")
    freeze("$(MPY_LIB_DIR)/micropython/urllib.urequest", "urllib/urequest.py")

    # umqtt
    freeze("$(MPY_LIB_DIR)/micropython/umqtt.simple", "umqtt/simple.py")
    freeze("$(MPY_LIB_DIR)/micropython/umqtt.robust", "umqtt/robust.py")

Some of these libraries are on another github repository. So we need to cline micropython-lib repo to use umqtt, urlib and requests. This way:

git clone https://github.com/micropython/micropython-lib

Now we can build the firmware again:

make -C mpy-cross
cd ports/rp2
make

And the resulting firmware now has the modules we need:

./picotool info /home/rafael/builds/pico/micropython/ports/rp2/build-PICO/firmware.uf2 
File /home/rafael/builds/pico/micropython/ports/rp2/build-PICO/firmware.uf2:

Program Information
 name:            MicroPython
 version:         v1.18-128-g2ea21abae-dirty
 features:        USB REPL
                  thread support
 frozen modules:  rp2, _boot, ds18x20, onewire, dht, uasyncio, uasyncio/core,
                  uasyncio/event, uasyncio/funcs, uasyncio/lock,
                  uasyncio/stream, neopixel, upip, upip_utarfile, ssd1306,
                  webrepl, webrepl_setup, websocket_helper, upysh, 
                  urequests, urllib/urequest, umqtt/simple, umqtt/robust

Ethernet and Raspberry Pi Pico

Ok, now let’s add ethernet support! Consider that the last section was an exercise (at least it was for me). So, the next operations can be done independently from the ones already discussed. The firmware sources are based on https://github.com/Wiznet/RP2040-HAT-MicroPython.

git clone https://github.com/rafaelaroca/RP2040-HAT-MicroPython
cd RP2040-HAT-MicroPython
git submodule add https://github.com/micropython/micropython-lib/
cmake CMakeLists.txt
cd libraries
make -C mpy-cross
cd ports/rp2
make

The above commands will build a complete MicroPython firmware with Ethernet support for the Raspberry Pi Pico with WIZNET W5100S (W5100S-EVB-Pico). Copy firmware.uf2 to the board and test it.

But, as we just did, we can edit the manifest files and add more features, like this:

freeze("$(PORT_DIR)/modules")
freeze("$(MPY_DIR)/drivers/onewire")
freeze("$(MPY_DIR)/drivers/dht", "dht.py")
include("$(MPY_DIR)/extmod/uasyncio/manifest.py")
include("$(MPY_DIR)/drivers/neopixel/manifest.py")

freeze("$(MPY_DIR)/tools", ("upip.py", "upip_utarfile.py"))
freeze("$(MPY_DIR)/drivers/display", "ssd1306.py")
include("$(MPY_DIR)/extmod/webrepl/manifest.py")

# Libraries from micropython-lib, include only if the library directory exists
if os.path.isdir(convert_path("$(MPY_LIB_DIR)")):
    # file utilities
    freeze("$(MPY_LIB_DIR)/micropython/upysh", "upysh.py")

    # requests
    freeze("$(MPY_LIB_DIR)/python-ecosys/urequests", "urequests.py")
    freeze("$(MPY_LIB_DIR)/micropython/urllib.urequest", "urllib/urequest.py")

    # umqtt
    freeze("$(MPY_LIB_DIR)/micropython/umqtt.simple", "umqtt/simple.py")
    freeze("$(MPY_LIB_DIR)/micropython/umqtt.robust", "umqtt/robust.py")

After editing the manifest file, let’s build the firmware again by simply running make.

Well, after all that, I am having trouble having WebREPL running. Details here: https://forum.micropython.org/viewtopic.php?f=21&t=11996

Anyway, the binary and ready-to-use firmware is here. If you cannot build, just download and use it:

https://bipes.net.br/firmwares/firmware_rpi_pico_ethernet_13022022.uf2

I had problems with the requests module. The fix I did is explained here:

https://github.com/micropython/micropython/issues/8298

BIPES and Raspberry Pi Pico Ethernet

WizNet is offering a low-cost Raspberry Pi PICO with Ethernet: the W5100S-EVB-Pico at about 9 dollars worldwide. For example, it can be purchased at Digikey here. There are firmwares ready to download and use based on MicroPython and CircuitPython.

If you want to quickly get started, just use this firmware I built:

https://bipes.net.br/firmwares/firmware_rpi_pico_ethernet_13022022.uf2

Next, just use BIPES with your RPI Pico (RP2040) + Ethernet.

Example 1: web client (HTTP GET)

Example result:

=== 
Trying to access http://bipes.net.br
Network connection status: True
HTTP Request result = b'BIPES Test: Live long and prosper!\n\n'
Date and Time from BIPES Server = b'2022-02-13 03:01:18pm'
>>> 
>>> 

Direct link to the program:

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

Example 2: send temperature using MQTT

Example result:

=== 
0
EasyMQTT connected
Network connection status: True
Trying to publish temperature to MQTT server...
EasyMQTT Publish - Session: ftxr7b Topic: temperature Value: 38.74783
Trying to publish temperature to MQTT server...
EasyMQTT Publish - Session: ftxr7b Topic: temperature Value: 40.62041
Trying to publish temperature to MQTT server...
EasyMQTT Publish - Session: ftxr7b Topic: temperature Value: 41.08855
Trying to publish temperature to MQTT server...
EasyMQTT Publish - Session: ftxr7b Topic: temperature Value: 41.08855
Trying to publish temperature to MQTT server...
EasyMQTT Publish - Session: ftxr7b Topic: temperature Value: 41.5567
Trying to publish temperature to MQTT server...
EasyMQTT Publish - Session: ftxr7b Topic: temperature Value: 41.08855
Error sending data. Network may be down.
Trying to publish temperature to MQTT server...
EasyMQTT Publish - Session: ftxr7b Topic: temperature Value: 40.15226

I removed the Ethernet cable during this program execution, and the try-catch detected it and alerted us (“Error sending data”).

Direct link to the program:

https://bipes.net.br/beta2/ui/#97vwqz

Updated version, ready to be saved and executed at BOOT:

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

IOT tab result:

Useful reference:

https://github.com/Wiznet/RP2040-HAT-MicroPython

BIPES, ESP32-CAM, SD-Card and web server!

Some minutes ago I posted a BIPES program to take pictures using ESP32-CAM and store them on the SD Card:

But we can go further and add a web server to the project and allow users to view the pictures taken using the webserver!

Direct link to the program:

https://bipes.net.br/beta2/ui/#56t5zh

Program:

Result:

After clicking on the image, we can see the picture captured by the ESP32-CAM (picture taken at midnight pointing to my Kindle, in terrible lighting conditions):