Connections to Raspberry Pi?

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

You can add CORS header
scriptImage11186157

Chrome@Win10 v 103 - this MB script works for me with local HTTP server@D1 Mini. The built-in led can be toggled with untitled script pic - 2022-07-06T011509.679 or by a browser.

Snap! served by http URL http://extensions.snap.berkeley.edu/snap/snap.html

But... without the CORS headers, it works either way for me.

.

It can be updated to use current version of the serial library.

That doesn't seem to work for me and I see

So it would seem that you are not actually having the same problem as me :frowning:

I'll experiment some more
[edit1] My Chrome was V102 - upgraded to 103 but still same behaviour

[edit2] Just tried using Vivaldi from one of my Pi and that works so it's looking like just an issue with my Win11 machine at moment - don't you just love computers :slight_smile:

[edit3] But my Pi software is fairly old (> 1 year ) so it it might be working for that reason

[edit4] Just tried Chrome on my Win10 laptop - that doesn't work either :frowning:

The issue isn't your Web Serial blocks - it's the use of JavaScript in the menus of the other blocks

I think I can get around that but I'm fighting battles on many fronts at the moment and I'd like to get local LAN webserver access working again as I use it in other projects :slight_smile:

Those seem to be the helpers only.
Broadcast should work as intended, and the variable-ID can be entered eg. "2:myVar".

I've got the VM2Snap method working (needed to re-import the List utilities library as was using old JavaScript version)

This Microblocks script lets us control the motor using variable "Motor" using values from -100 to 100 to control speed and direction

WEMOS_D1_Mini_I2C_Motor_usingviaVM

And this is a corresponding Snap! project to control it

Username=cymplecy&ProjectName=WEMOS_D1_Mini_I2C_viaVM

NOTE: After loading the Microblocks script into the WEMOS D1 mini, remember to close Microblocks before running the Snap! script otherwise you get a clash between the two programs over the com port

Obviously, each of the scripts could be made to look nicer :slight_smile:

Very interesting. The WEMOS microcontroller seems difficult to source, particularly in volume for classroom purposes. Other than eBay, have you encountered any other retailers stocking them with any regularity? You also mentioned the NodeMCU. Have you tested that yet? I may order one and give that a shot as well.

Thanks.

I can easily get WEMOS D1 mini from Ebay or Amazon here in UK
https://www.amazon.co.uk/Development-NodeMcu-ESP8266-Internet-Compatible/dp/B08QZ2887K/ref=sr_1_8?keywords=wemos+d1+mini&qid=1657214982&sprefix=WEMOS%2Caps%2C91&sr=8-8

I'm having trouble finding a cheap source for the WEMOS Motor shields at the moment though

Only place I can find is on Ebay but relatively expensive
https://www.ebay.co.uk/itm/122438069610?hash=item1c81e0ad6a:g:nBcAAOSwU8hY6jRI&amdata=enc%3AAQAHAAAA4By0KL%2Fkp1V6shgkur5bpZPu0396%2F4z9p1oFzV%2BjG4TCPHFJsLUXKqOVhsrNA7bmzUPprDpAi72mvHTWuWpFjU5WiJlJarSpftDz%2B1%2F2PlxGfS%2FVntdQMmyf5wuZIgGOVkcSWcC5l7V36ZjrubMYBdzZPgdcQrmB6OmHx%2FBXS1Yu7cBmasXcdy8x3GbpF8Gk3tHVE66YQibHC3LIvk3gIcEBz3Nc2HmHVGHqe%2B3zaF0TgFGFhOJa36G0bq%2FzCFrzAn5VrY6R1F4MOVjAiV4p5OJbEL2W6BjjuCdnUs4hv%2Fjd|tkp%3ABFBM7vvvm7tg

But the NodeMCU and its Motor Shield seem readily available and are plug and play with no soldering and no need to flash new firmware :slight_smile:

https://www.amazon.co.uk/DollaTek-NodeMcu-ESP8266-Development-Expansion/dp/B07DK68J37/ref=sr_1_2?crid=31Q36RKDYPYAT&keywords=nodeMCU+motor+shield&qid=1657215341&sprefix=nodemcu+motor+shield%2Caps%2C57&sr=8-2

I followed the UK Amazon link that you provided. These items are not available to customers in the U.S. Not sure why they can be obtained in one location but not the other.

I did find these on our Amazon. Not sure if they ship to the UK.
https://www.amazon.com/CANADUINO-WEMOS-Motor-Driver-Shield/dp/B07CQ8DLSD

I think I can manage to source the rest too. Thanks for the info.

The Trump trade war?

Just revisited my simple Arduino sketch and standardised it to accept numbers from -100 to 100 to control the motor

#include "WEMOS_Motor.h"

int pwm;

//Motor shield I2C Address: 0x30
//PWM frequency: 1000Hz(1kHz)
Motor M1(0x30,_MOTOR_A, 1000);//Motor A

int incomingByte = 0; // for incoming serial data

void setup() {
  Serial.begin(115200);
}

void loop() {
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();
    if (incomingByte > 127) {
      M1.setmotor( _CCW, (256 - incomingByte));
    } else {
      M1.setmotor( _CW, incomingByte);
    }
  }
}

Together with it's Snap! script

Username=cymplecy&ProjectName=WEMOSusingArduinoLib2

We have the Wemos units on order and will try this out as soon as they arrive. (Thanks so much!)

P.S. Is another Birds of a Feather session on physical computing planned for Snap!Con?

Only if someone organizes it! Nobody proposed one ahead of time but we'll have a way to schedule one during the conference.

As part of playing around with this, I've created a simple Microblocks block to control the motors on the WEMOS V1.0 shield

module WEMOS D1 I2C motors
author 'Simon Walters'
version 1 0 
choices motors A B 'A+B'
description 'Control the speed of motors using a WEMOS D1 mini I2C V1.0 Motor Shield '

spec ' ' 'motor' 'WEMOS D1 I2C motor _ speed _ :PWM freq _' 'menu.motors num num' 'A' 0 '100'

to motor motor speed optionalFreq {
  local 'freq' 100
  if ((pushArgCount) > 2) {
    freq = optionalFreq
  }
  '[sensors:i2cWrite]' 48 ('[data:makeList]' 0 0 ((freq >> 8) & 255) (freq & 255))
  local 'direction' 1
  if (speed < 0) {
    direction = 2
  }
  speed = (absoluteValue (speed * 100))
  local 'motor data' ('[data:makeList]' 0 direction ((speed >> 8) & 255) (speed & 255))
  if (('[data:find]' 'A' motor) > 0) {
    atPut 1 (v 'motor data') 16
    '[sensors:i2cWrite]' 48 (v 'motor data')
  }
  if (('[data:find]' 'B' motor) > 0) {
    atPut 1 (v 'motor data') 17
    '[sensors:i2cWrite]' 48 (v 'motor data')
  }
}
Save code as .ubl file in your Libraries folder (on my Win 11 - that's in C:\Users\siwal\Documents\MicroBlocks\Libraries

Excellent! Now that the Microblocks script has been developed for the Wemos, is it feasible for Snap! on a PC to talk to MicroBlocks on the microcontroller?

There are two documented methods using the Web Serial library in this thread :slight_smile:

I haven't fully documented the WiFI webserver approach but I'll do so