-
Hi,
I got a M5Stack thing with several I2C sensors. All work with Espruino. Awesome!
I got a LEGO+ module (AKA DC Motor) which can control Lego motors from the Mindstorm series. It works using M5Stack's microPython. Capabilities are limited to turn motor to speed -255..255 and read the encoder absolute values. The actual logic is handled by a Atmel Mega328. Here an example how you talk to it via Arduino code.It behaves as a I2C slave device (addr 0x56), but I cannot make it work using Espruino.
M5Stack has has several similar modules with on-board controller and I assume the way to talk to them is similar.
Does anyone have an example of talking to those M5Stack modules which are I2C slave devices? Any of them?This code does not work:
I2C1.writeTo(0x56, 0, 100, 0, 2);
which is (supposedly) matching line 43 of the LEGO_PLUS.ino sample code.
What am I missing? -
-
-
Nothing else running on it. I had more, but to debug this problem I removed anything else (not that much was running since it's very much space constrained).
Since the point is to display whatever is sent (up to 6 bytes, since it's a 6 character display), not much chopping up possible.
For power: It's using a USB power adapter. Never had problems with it.
Two different ESP8266 modules. Both with ESP12E: Wemos D1mini and a random NodeMCU module. -
-
Hi,
I have a small ESP8266 module which is supposed to receive simple data via simple TCP. The net module should do that and it works mostly:
var server = net.createServer(function(socket) { socket.on('data', function(data) { try { let a=JSON.parse(data); console.log(">"+JSON.stringify(a)); } catch(e) { console.log("ERROR: ", e); } }); socket.end(); }); server.listen(1234);
On the sender side I do a simple test via netcat:
for i in {0..4} ; do echo "{'toggle':$i}" | nc 192.168.21.105 1234 ; done
But what I get on the Espruino side is:
{"toggle":0}
{"toggle":2}
{"toggle":3}
{"toggle":4}
{"toggle":0}
{"toggle":1}
{"toggle":3}
{"toggle":4}
{"toggle":0}
{"toggle":1}
{"toggle":3}
{"toggle":4}
{"toggle":0}
{"toggle":1}
{"toggle":1}
{"toggle":2}
{"toggle":3}
{"toggle":4}which is not what I'd expect from TCP. I should see 0, 1, 2, 3, 4.
Even if I send one string at a time (and not 5 in a loop), it gets lost in about 20% of the cases.Am I doing something wrong? Is the net module on ESP8266 not working reliably?
-
Digging a bit around, this works and it's reliably working: Use espruino -o x.js MYPROGRAM.js and then upload the temporary output, which resolves all require() modules via wifi (nc ESP32IP 23 < x.js)
That proves at least that whatever the espruino command does, seems to work. The problem might be an intermittent reset caused by the serial port.
-
Hi,
I got a neat ESP32 board and tested Espruino (1.92) on it. Works like a charm when using the Web IDE. Uploading via NPM espruino module works. About once in 10 times. It sends data (-v switch is very useful here), and it usually does something, but often it seems to forget everything immediately, like if there is a reset() after upload.
E.g. I have a small program uploaded which:
- Sets up I2C1
- Loads SSD1306 library and initializes the OLED (connected via I2C)
- Prints text on the OLED. This works 100%. The OLED is initialized and text appears.
- Supposed to print more every second (via setInterval()). That does work once in about 10 times.
In the cases where it does not work, the serial console is usually no longer working until I reset the board. In the few cases where the console is accessible, I can connect via minicom, and I see nothing being remembered of my program. Looks like a reset happened. Namely the variable g I use for the OLED is not defined anymore. No wonder it cannot write anything to the display.
The Web IDE works. Always.
Any idea what's causing the NPM espruino to not work as well as the Web IDE?
Harald
- Sets up I2C1
-
-
-
ROR is ROtate Right. ROL is ROtate Left.
Difference to a normal shift is that in a shift all bits move one bit position. The leftmost in a shift left or rightmost in a shift right usually gets a 0.
In a rotation the bits move in a circle: in a left shift bit 7 moves into bit 0.
See here: https://en.wikipedia.org/wiki/Bitwise_opĀeration#Rotate_no_carry -
The LiPo is fine. The connectors too. The voltage (measured with a simple multimeter) is fine too.
And I don't even have to touch anything. It reacts slightly by just nearing my hand near the LiPo.
Which is why I think this is a capacitance thing, but I cannot explain this.What could make a WS2812 think that blue data should be sent to the red LED, and at high intensity (ike shifts 3 bits left)? Consistently.
-
I got a nice STM32F4 Discovery board for quite a while. Recently installing Espruino (1v80) on it and having a significant amount of fun learning JavaScript. But now I got an electronical problem (unlikely Espruino, but maybe STM32 related):
See here
for what happens.Connections: STM32F4 board connecting to PC (for terminal) and a LiPo and switched regulator to the 5V input. B15 is connected via a jumper cable to Din of the WS2812 chain. GND too. Vcc of the LEDs is not using 5V as that gives me those high intensity colors I get too when I touch the LiPo. So I know that 3.3V is not sufficient to drive a 5V WS2812. Fine. No issue. I should drive it with 5V after all.
The problem is that I'd like to understand the mechanism why when I touch the LiPo, the light intensity is reproduceable different. It's still working as sending data to the WS2812 still makes the lights move in circles. The colors change:
Low intensity blue gets high intensity red. High intensity blue gets low intensity green.
Low intensity red get high intensity green. High intensity red gets black.My understanding of R and C and transient spikes cannot explain this at all. The WS2812 is after all a digital device.
Anyone an idea what happens?
I know the fix is to drive the WS2812 with 5V, or drive them with 3.3V and have Vcc on the WS2812 get 3.3V (or less than 3.8V). That's not the problem. I'd like to understand why those LEDs behave odd when I touch the LiPo.
-
-
Ok, I officially am a JS noob...thanks for the explanation. At first I did not see the difference, but I saw what to check.
I kind'a get it now and this helped:var glow=function(led, stp) { var intensity=0; var dir=1.0; var this_led=led; var this_stp=stp; function intensity_step() { intensity+=dir*this_stp; if (intensity>=1.0) { intensity=1.0; dir=-dir; } if (intensity<=0.0) { intensity=0; dir=-dir; } analogWrite(this_led, intensity); } return intensity_step; }; var led1=glow(D13,0.01); setInterval(led1, 2);
Is that behavior a generic JS thing or the implementation of setInterval()?
-
Different, slightly unrelated question:
I tried to usevar led1=flow(D13); setInterval(led1(0.01),2);
but I get an error:
>setInterval(led1(0.01),2); =undefined Uncaught Error: Function or String not supplied! at line 1 col 25 setInterval(led1(0.01),2);
Anyone an idea why that does not work? led1 is a function after all when I use it as led1()...
-
-
-
Hi,
Playing more with the STM32F4 Discovery...trying to make some WS2812 LEDs work. Just learning about Espruino and JavaScript. So far I like both a lot.
Small problem though: The data sent via
SPI2.setup({baud:3200000, mosi:B15}); SPI2.send4bit([16,16,16, 1,1,1, 8,8,8, 16,0,0, 0,16,0, 0,0,16], 0b0001, 0b0011);
seems to be G, R, B which is slightly unusual and unexpected.
Above line lights up 6 LEDs: gray16, gray1, gray8, Green, Red, BlueI'm ok with RGB or BGR but GRB looks like an error. Is this a known bug?
I'm running Espruino 1v80.1 for the F4 Discovery.
-
No, the example of 4-20000 LEDs was just that: an example. I know I can change the brightness of the 4 LEDs I have via setting the duty cycle via setInterval(). No issues. CPU power is enough even for updating once in 5ms per LED.
I am quite confident thatI cannot do the same if I had 20000 LEDs. The question was: how do I know when the CPU won't be able to catch up anymore?
And the setBusyIndicator() does that.BTW, I checked and this is the result:
// Glow 4 LEDs var glow=function(led) { var intensity=0; var dir=1.0; var this_led=led; function intensity_step(n) { intensity+=dir*n; if (intensity>=1.0) { intensity=1.0; dir=-dir; } if (intensity<=0.0) { intensity=0; dir=-dir; } analogWrite(this_led, intensity); } return intensity_step; }; var led1=glow(D13); setInterval(function() { led1(0.01); }, 2); var led2=glow(D14); setInterval(function() { led2(0.01); }, 2); var led3=glow(D12); setInterval(function() { led3(0.01); }, 2); var led4=glow(D15); setInterval(function() { led4(0.01); }, 2); // See how busy the CPU is setBusyIndicator(D11);
Attached the wave form of D11 when changing only one LED. You can see this is repeating at 500Hz, and it's already using 25% of CPU.
4 of those keep the CPU close to 100%.Please no one comment on the horrible code. I'm just learning JavaScript and I already figured out the code is sub-optimal in so many ways ^_^
PS: Forgot to mention: This is on the STM32F4 Discovery board.
-
-
Hi,
While playing with Espruino and having a fun time learning JavaScript in general, I wonder:
How busy is the CPU?
The point came up when I created a "glow LED" function with gets called via setInterval() every 5ms.
It works fine for 4 LEDs, but I wonder when it will start to drop things or simply run late. Can I do 10 LEDs? What about 20? 200? 2000?This is not an actual problem (yet), but it would need only some slow JavaScripts calls to keep the CPU busy, and I'd rather know that I am either close to the limit or far, far away from it.
Harald
Thanks for the quick reply Gordon!
And yes, setup is done:
Tried with [] and without, with 100 and 400 kbit/s
I cannot change the pins. I can see/detect the slave Mega328. I2C1 works for everything I throw at. I think I'm missing something to make the Lego+ module "start" somehow.
My hope is someone uses a M5Stack module and loves using Espruino on it too.