Connections to Raspberry Pi?

Hi, Glen.

Another approach to this problem is to run MicroBlocks on the board and communicate with it via Snap! You can find some helpful tutorials and examples on the MicroBlocks Wiki.

MicroBlocks already runs on the $4 Raspberry Pi Pico. From what I've read, the Pico W is similar enough to the original Pico that MicroBlocks should run on it already. We plan to add WiFi support for the Pico W we can. (I believe the underlying C/C++ library for WiFI is still under development).

Another possible option would be the new PickBricks board from Robotistan, which includes a motor controller. They just ran a wildly successful Kickstarter. Although the full PickBricks board is more than you need (and probably too expensive), Robotistan may sell the motor control board separately. (Oddly, their board lacks an H-bridge so the motor direction can't be changed.)

However, I agree with Simon: the cheapest option available right now is the Wemos D1 mini + motor shield for $10. The Pico W itself is low cost but it's not clear if anyone will make a low-cost motor shield for it. You could design your own board, but in small quantities the cost of the components alone would probably exceed $4, so the total cost would be more than the Wemos D1 mini option.

If you use the Wemos D1 mini, you could run a very simple MicroBlocks HTTP web server on the D1 mini and control it wirelessly from Snap!

For projects that don't involve Snap!, you could also have students use MicroBlocks directly. MicroBlocks runs in the Chrome/Edge browser and supports many educator-friendly microcontrollers including the micro:bit, Wemos D1 mini, and Raspberry Pi Pico. It also runs on the Adafruit Metro M0 board, which works with Roger's shield.

Feel free to email me if you'd like to explore any of these options.

We’ll order some Wemos D1 units and follow up after they arrive. Thanks!

Ah, maybe you're right. Thanks.

Well - not having a lot of luck getting my motor shield to work :frowning:

Just trying it with basic Arduino sketch and it's not moving

Some stuff out on the internet says pads underneath the board need to be soldered together, lots of stuff out there talk about re-flashing the firmware as the original factory installed is considered buggy :frowning:

A bit of a disappointment to say the least

I obtained a V1.0 board but there is also a V2.0 board and I think there must be a good reason for that :slight_smile:

Or of course, I may just have been unlucky with this particular board

Well - perseverance has paid off :slight_smile:
So, it seems that some of these boards (certainly mine) come with really faulty firmware!!!!

I had to dig out a USB->TTL board from my cupboards and re-flash the firmware following these instructions
https://www.letscontrolit.com/wiki/index.php/WemosMotorshield
Note - I had to swap around the Rx/Tx connections before I could communicate to the board

I had to do everything in those instructions including soldering the pads underneath the board

But now I have it controlling a motor using Arduino sketch :slight_smile:

That’s great! Now that you can control the board, what is the next step in communicating with Snap! ?

Just seeing if I get Dardoro's micropython REPL idea working

(I've only ever played with it once before so having to learn stuff!) :slight_smile:

Currently failing to invoke the right spells to copy a module called d1motor.py onto the board - needs something called rshell and I'm not having much luck with that :frowning:

Tried something call mpfshell - got a bit futher - but once I actually connect to my board - it throws me back out to command prompt :frowning:

Going to have a little play seeing if I can get Microblocks to talk directly to the I2C motor interface

Had an idea- switched back to mpfshell but opened the com port at launch - that worked :slight_smile:

Got the d1motor.py file across and just in REPL at moment seeing if I can get that to work

image

And I had the motor working direct from the REPL but sending same set of commands from Snap! and nothing is moving :frowning:

image

I assume you are providing external power to the VM and GND pins...

You could check the motor output voltages with a meter at full power in each direction. The polarity should reverse when the direction reverses. If you have a 'scope, you could check that PWM signals are being generated.

Where did you buy your Wemos motor shields? I see them on Ali Express and EBay.

I'm actually cheating by using 5V from the USB - but it works fine using straight Arduino code and directly using the REPL so it's not a hardware issue :slight_smile:

The motor is basically the guts of an SG90 servo so it doesn't draw much current

I was going to Liverpool Makefest and tweeted the night before to ask if anyone going had one - and a hardware supplier had one left in stock and brought it along for me :slight_smile:

Going to have a rest from controlling via REPL and try reverse engineering the Arduino library to control it direct via I2C in Microblocks

Test project to blink a built-in led of the D1 mini board with Micro Python firmware
untitled script pic - 2022-07-04T001039.990

CRLF seems to be required by REPL.
untitled script pic - 2022-07-04T001715.303

Nice trick! Computer USB ports are usually limited to 500 mA so that trick should work for Glen unless his homemade motors draw more than ~400 mA (assuming the Wemos D1 itself needs about 100 mA).

Let us know if you you figure out how to control the motor from MicroBlocks. The I2C motor controller chips I've used have usually been pretty easy to use. Sometimes it is just a matter of setting the PWM duty cycle in one register and the direction in another. I hope this is one of the simple ones.

Thanks

Got there now :slight_smile:

image

ProjectName=WEMOSMotorviaMicropython

So initial thoughts are

Uploading the micropython firrmware and then having to add the d1motor module is quite a lot of work and involves having the right tools installed on the computer. And I can easily imagine that this would be even more problematic , if not impossible, from a Chromebook. This would be fine to do once at a school/college but might render the combination unusable if it was played about with at home

Having to click on the serial port and then click connect each time the port is opened is a bit clunky but it does work :slight_smile:

Great that you got the Python solution working!

The setup using MicroBlocks might be easier, and it would work on a Chromebook. You don't need to install an app, just run MicroBlocks in the browser and use the MicroBlocks "update firmware on board" menu command to install the MicroBlocks interpreter. Then we'd just need a library for the Wemos motor shield (which I'd be happy to write if you're willing to help me test it).

Students would then be able to write MicroBlocks scripts to control their motors. Since MicroBlocks is live, they can test their scripts as they work. And since the code runs right on the Wemos D1 mini, it doesn't need the laptop. Students can disconnect from the laptop, plug in a battery, and run their project anywhere.

Alternatively, one can write a simple web server in MicroBlocks (there is an example that can be copied and modified) and control the motor via HTTP requests. One could build a Snap! program to send those requests -- or just issue the requests from a browser.

Did you find a datasheet for the motor controller chip? If so, could you tell me the part number so I can take a look?

Yes please - I'm not getting anywhere at guessing what I need to do with using I2C from within Microblocks

I think that Glen isn't after this. I think he wants students to use Snap! scripts that can be doing things on the screen, making music AND controlling some piece of kinetic art (If I've understood his requirements anyway)

I think this would be a possible alternative approach to using Micropython REPL requests vai serial

Has the advantage of not needing to be physically connected to the WEMOS with just the slight complication of needing to connect to the school/college WiFi (which may or may not be restricted by an IT Dept)

AFAIUI, the WEMOS Motor Shield V1.0 uses custom firmware for a separate I2C controller chip

I've been trying to read the Arduino sketch that works to guess at what is needed to send to it to get it to turn the motor.

But I've no real expereince of writing I2C stuff - 99% of time , I've just used someone else's libraries.

The Arduino sketch that works is here

The library it uses is here

Module doc: Motor Shield — WEMOS documentation
The motor control chip is a "dumb" dual H bridge controller TB6612FNG.
The I2C part is just an application running on the STM32F030F4 : GitHub - pbugalski/wemos_motor_shield: Alternative firmware for Wemos Motor Shield

BTW.1, STM32@48MHz, 16K Flash, 4K SRAM appear to be competitive to low-end Arduino boards.

BTW.2, there are thin wrapper boards built over TB6612FNG (dual, quad) that are available for 0.5 - 2 $ from Ali or european sellers. Sometimes sold as HG7881, L9110.

HG7881


There's a V1 and V2 board - they use different libraries

I've got a V1 board

I'm thinking that it may be better to switch away from the WEMOS D1 mini approach and use a NodeMCU (also EPS8266 based) with it's motor shield

It seems to be more readily available at the moment and has the advantage of being much simpler to control as it just a simple H-Bridge controller directly driven from 4 of the ESP pins without any of the faff of I2C

I've got one working at the moment

[edit] 5Jul22 09:00BST

I decided to try just having a simple Arduino sketch to read the serial port (until I get some success in using I2C in Microblocks) and control the motor that way

image

[edit] 5Jul22 10:55 BST

I have it working in Microblocks using I2C - details to follow! :slight_smile:

[edit] 5Jul22 11:18 BST

So, this is standlone script in Microblocks that just ramps the speed up in each direction

Sorry for taking so long to get it going - I was previously making a silly mental mistake in transcoding the Arduino byte sequences and got my hex and binary mixed up #SchoolboyError :slight_smile:

So next task is to try and use the Microblocks HTTP server blocks to get it listen for commands from Snap!

Not done that before so that may take me a bit of time :slight_smile:

This will be extremely helpful, not only for the immediate application, but also as a general concept and example going forward. Thanks for all the thought and experimentation that everyone has invested.

I've got the Microblocks HTTP server working but unfortunately hit a snag accessing it from Snap! :frowning:

Certainly having some "fun" with this one

And I did get it working with the Turgut's VM2Snap blocks

But they rely on JavaScript being enabled so would have to work around that issue before it becomes viable for general use