Connections to Raspberry Pi?

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

Thanks so much for piloting this. Once we verify that we can replicate the method, we'll develop a document with this information.

Glen
is the connectivity requirement only WIFI based ? Or is std Bluetooth acceptable as well ?

The discussion about wireless is just an artifact. I noticed that Raspberry Pi had released a Pico W (for wireless) for $6 and inquired about the possibility of controlling it from Snap! Simon recommended the Wemos D1 mini as a better solution.

However, Bluetooth or even a direct connection via USB would be fine. In another project, Rich Nguyen is looking into the possibility of using long-range LoRa chips (LoRa - Wikipedia) for remote sensing, but we're currently not doing anything with motor design and fabrication projects that requires remote control. Since the schools primarily use Chromebooks, any solution does need to work with that platform.

It's great that Simon was able to make a MicroBlocks library for the Wemos D1 motor shield. It's too bad that there doesn't appear to be a US distributor for that motor shield. Their official distributor seems to be the Chinese company Ali Express. Unfortunately, it is difficult for many US schools buy stuff from either Ali Express or from EBay.

The NodeMCU shield is more readily available than the Wemos motor shield in the US (e.g. from Amazon). Unfortunately, it's expensive at $10-12. On the up side, since it is a shield, it creates in a robust physical "package"; no loose wires that could get pulled out.

Good to know! That is a very low-cost option. I see that it is available for $1.99 from a California company called Banana Robotics. This board could be combined with the Raspberry Pi Pico for a total of about $6 -- plus the cost of the jumper wires.

Independent of the hardware, there are a number of equivalent ways for Snap! to control motors: Snap! sending commands to the Python REPL, Snap! sending commands to MicroBlocks, or Snap! sending commands to an Arduino program. The transport could be web serial or WiFi. All of these solutions work with Chromebooks.

Setting up the firmware on the board may be easier for some of these options than others (e.g. MicroBlocks), but that may not be an important consideration since the firmware can be pre-installed by the teacher and students can just plug in the board and use it from Snap!

That said, I'd still argue that MicroBlocks is the nicest language to run on the board itself because it is a blocks language. Students who are curious -- or teachers who want to extend the firmware capabilities -- can do so more easily in MicroBlocks than in Python or Arduino C++.

I'm sorry I can't organize a SnapCon BoF around physical computing. I'm teaching a PD course for K-12 teachers the directly conflicts with SnapCon! However, if someone else organizes one and the timing works out (e.g. if itis on Saturday) then I will try to join.

I agree about shields. We have gotten much better results with groups of children when a shield reduces the number of wires that may be pulled out.

We don't (yet) have extensive experience with MicroBlocks, but I can say that use of native Arduino sketches at the middle school level has resulted in a high percentage of students in local schools dropping out of the STEM track due to frustration. It stands to reason that if they're already successful with Snap!, the extension to MicroBlocks should be a more seamless transition.