Charlie drums

A slow drummer but nevertheless he drums:

but making he move an arm in just 2 simples steps was frustrating… spent a whole night fiddling with micropython ‘mindstorms’ library… sending script with ‘ampy’ gave stupid errors (like ‘RuntimeError: There is not a motor connected to port B.’) or even worst leading to firmware crashing so badly that I had to take the battery out of Charlie’s head at least 5 times.

So I gave up trying to use something not documented at all and reached for help from a great ROBOTMAK3R: Nard Strijbosch’s Unofficial LEGO MINDSTORMS and SPIKE Prime low-level hub module documentation

So instead of using ‘mindstorms.Motor’ I used ‘hub.port’ own motor class:

leftArm = port.B.motor
leftArm.run_for_degrees(10, speed=-100)
 while leftArm.busy(1):
     pass
 leftArm.run_for_degrees(10, speed=100)
 while leftArm.busy(1):
     pass

and now everytime I run a script through ‘ampy’ it works – except on first time after powering on Charlie’ – it seems I have to first access REPL and only after exiting it accepts ‘ampy run’ commands – if I forget to do that, Charlie turns itself off.

I am a bit disappointed with motor speed. After using the Charlie activity from the App (scratch based) I was expecting faster movements with micropython:

I need to look into the scratch demo… but I only managed to use it on my phone (on my tablet the App doesn’t load any activity) and coding is terrible on a small screen (not to mention debugging!!!).

I am not enjoying this new “paradigm”. Maybe the future is Apps and smart devices but I like to think that I can choose my own future. Can’t wait to see Pybricks running on this.

–edited–

the scratch demo controls the motors through speed only, not through position. I feel cheated 😀

Linux and the LEGO Powered Up MINDSTORMS

Nothing new here, just my personal notes with the LEGO Hub from 51515 MINDSTORMS Robot Inventor Set.

Most of it based on this post by Jason Jurotich.

I have a LEGO 51515 set, thanks to the ROBOTMAK3RS community (and still not sure yet if I am willing to pay so much money for this set).
I have an Android Lenovo tablet and an Android Samsung phone. Installed LEGO MINDSTORMS App on both but only can managed to use it on the phone – the tablet doesn’t get Activities so I could not even make Charlie play the drums.

I also have a Ubuntu Linux laptop. It will have to work – last time I revived a Windows 10 virtual machine it took me a whole night just to update it in order to install LEGO App. No way!!

So tanks to Jason post I can connect my laptop to the Hub:

sudo rfcomm connect hci0 A8:E2:C1:96:5B:9A

this gives me a ‘/dev/rfcomm0’ serial device and I can access the REPL environment in 2 different ways:

directly through a terminal client like ‘picocom’:

picocom /dev/rfcomm0 -b 115200

with a more proper tool like ‘rshell‘:

rshell -p /dev/rfcomm0 repl

When accessing the REPL, the hub is sending values so we need to Ctrl+C to get the prompt.

I found out that accessing the REPL through ‘picocom’ lead to strange behaviors afer a while (like commands being executed but not returning to the prompt and after a while not being able to access again, like if the Hub was rebooting immediately after accessing it) so I am now using ‘rshell’.

I also installed Adafruit ‘ampy’ from pypi. This way I can send and execute a micropython script from my laptop without accessing the REPL:

ampy --port /dev/rfcomm0 run test.py

But since I know nothing about LEGO micropython environment I will use REPL a while more (before flashing Pybricks on it and probably forgetting LEGO firmware like I did with MINDTORMS EV3 original application once I discovered ev3dev).

When accessing the REPL environment this is the welcome message:

Welcome to MicroPython!
 For online help please visit http://micropython.org/help/.
 Quick overview of commands for the board:
   hub.info()    -- print some general information
   hub.status()  -- print sensor data
 Control commands:
   CTRL-A        -- on a blank line, enter raw REPL mode
   CTRL-B        -- on a blank line, enter normal REPL mode
   CTRL-C        -- interrupt a running program
   CTRL-D        -- on a blank line, do a soft reset of the board
   CTRL-E        -- on a blank line, enter paste mode
   CTRL-F        -- on a blank line, enter filetransfer mode

of course ‘hub.info()’ and ‘hub.status()’ only work after we ‘import hub’ library – something probably obvious for someone used to (micro)python and REPL but not so obvious for newcomers.

Other important methods in this library

‘hub.battery.info()’:

>>> hub.battery.info()
{'temperature': 23.8, 'charge_voltage': 7591, 'charge_current': 251, 'charge_voltage_filtered': 7583, 'error_state': [0], 'charger_state': 0, 'battery_capacity_left': 80}         

‘hub.repl_restart()’ – I had used this method a few times today… and I hate reboots!

‘hub.power_off()’

So lets find out if I can make Charlie play the drum with micropython.

Back to MIDI

… and again and again 😀

So the LEGO Laser Harp v2 is almost done. A few more bricks here and there.

But it the meanwhile I had to test my MIDI ideas… and got a MiDiPLUS miniEngine USB as a cheap portable MIDI sound engineso I don’t have to use a computer (yeah… as if!)

Amazon.com: midiplus miniEngine USB MIDI Sound Module: Musical Instruments

Then I got back to the MINDSTORMS pneumatic pressure sensor idea and made a sort of LEGO MIDI Trumpet:

Then I got carried away and made my own LEGO MIDI Drum Kit:

All these using USB MIDI Adapters and plain MIDI equipment (I now also have a MIDI Merger). Even joined my MIDI keyboards to the MIDI network thanks to Patchbox OS running on a Raspberry Pi with a USB MIDI adapter for the older keyboard (DIN5) and plain USB cables for the newer ones.

But the original idea was making MIDI instruments without cables and gadgets (except for the WiFi dongle) so I got a little back again and made a few tests with multimidicast (ipMIDI).

The Drum Kit works great with MIDI cables… but extremely bad with ipMIDI when using the Raspberry Pi with Patchbox OS as an ipMIDI gateway. High latency and poor sensibility when using MODEP software generators.

So gave up MODEP and jack and used just a USB MIDI adapter to connect the ipMIDI gateway to the MiDiPLUS miniEngine USB. Much better… but still some latency.

Then… decided to try Patchbox OS own WiFi hotspot instead of my house access point. And latency droped HUGELY!

So I just need to make a few more adjustments to finish my LEGO ipMIDI Drum Kit. Then will test how this thing scales out with more ipMIDI instruments.