Hey i was writing a Code in the Arduino-IDE and would like to build the same code in S4A.
Actualy i look for a possibility to communicated between 3 Arduinos to send messages.
Is there a way to do the same with S4A?
Hey i was writing a Code in the Arduino-IDE and would like to build the same code in S4A.
Actualy i look for a possibility to communicated between 3 Arduinos to send messages.
Is there a way to do the same with S4A?
Just to be clear.
You DO NOT WANT the Snap! project running on a desktop "talk" to an Arduino board?
Do you want to make a program FOR a microcontroller board?
You ask questions about S4A https://s4a.cat/ or Snap4Arduino https://snap4arduino.rocks/?
Maybe @bromagosa can provide some info.
You DO NOT WANT the Snap! project running on a desktop "talk" to an Arduino board?
Not sure if this is the point, but i want the board to communicate to an Serial Monitor or something else who can get and send a message to the board. I thought about using the ask-and-wait block to get the text and then send to via the board.
I want to send a message from Board A to B and then from B to C and in the other direction.
The target is that f.e. person A can input a text, which get encrypted and been sended to B wo get the message show and send it to C wo decrypt and see the message to.
Do you want to make a program FOR a microcontroller board?
I want to use the program for the ESP D1 Mini.
As much as my understanding is actualy about Snap4Arduino i don't make a run alone code for the arduino, but more can set and read the pins. Or i'm wrong with this?
You ask questions about S4A https://s4a.cat/ or Snap4Arduino https://snap4arduino.rocks/?
I meaned Snap4Arduino, didn't recogniced that S4A is for scratch.
A board programmed with the Firmata can be driven to get/set pins by serial/USB port messages.
I'm unsure if software serial, with decent speed, can be made this way.
What do you get so far? The "Arduino" category seems to be self-explaining
As a side note, Wemos D1 is capable enough to be driven by Microblocks https://microblocks.fun/.
First thanks for the response, helpes me a lot to get rid of some misunderstandings. I hope i got a little better understanding of how snap4arduino works and thought that it should be enougth if i can send a String to the arduino. I would like to run the sending part on the arduino.
I was crawling a bit through the form and the manual, if i find something that helps me to do that.
Especialz i tryed Firmata and SerialPort.
At my Uno i get connected to Snap4Arduino but if i try the same with my ESP8266, even with the adding i found in git for the StandardFirmate it don't work. I don't want to use Internet, so i didn't tryed to use the FirmataWifi for ESP.
I just trzed ones but as sone as i added some code in the loop from StandardFirmata i couldn't get my Uno connected.
I found your expamle code for the SerialPorts, but don't get it to run.
Is the SerialPort using the HTML-Server from Snap or can it also us a Port like when i connect to an arduino to send?
I also took a short look into microblocks and it's extensions, but i don't found just an option to make a second serial write port but not a second to read. So i don't think it will help me a lot without much more time to find a way to do that.
The "Serial Ports" library is intended for the vanilla Snap! and works stand-alone using Web Serial API. I never tested it with Snap4Arduino, but it may interfere with "Snap4Arduino connector" Chrome extension.
Web Serial API requires permission to access device ports. If the browser shows no port selection dialog you should check "Site settings". My localized browser shows device permissions stored during my old experiments
There is a How Does Serial Communications Work? | MicroBlocks Wiki made by @tguneysu . Software serial is implemented as blocks
I work on the app and not the browser, it there also something i should look for.
Snap4Arduino desktop?
It's a NW.js app. I don't know how to debug permission/compatibility problems in this environment.
https://snap.berkeley.edu/snap/snap.html
.
Minimal Arduino sketch and test script
I tested a little bit with the SerialPort.
When i try your code
void setup() { Serial.begin( 115200); while (!Serial) {} } void loop() { if (Serial.available()) { Serial.print( "Echo:"); Serial.write(Serial.read()+1); } }
with more then one sign like ABC instead of A, i got "Echo:AEcho:BEcho:C" as response.
But as sone as i wrote
Serial.print("Echo:");
Serial.write("AB");
Serial.write("CD);
i just got "Echo:ABCD"
Sometime i also get an endless loop from the response, so instead of Echo:A i get Echo:AEcho:AEchos:A ... for like 150 signes, happens more likely when i don't use Serial.read and instead us a determiened String but isn't overall consistent. I think that shouldn't be a big problem overall, just have to make sure the probgram just send it once.
A bigger Problem where i don't know why it happens and how to fix is that i get always the same answer over the serialPort. I tryed a restart of the browser and pc, cleared all browserData chrom alowed me to, started the arduino again and also disconnected and connected it.
If i use the SerialMonitor from the ArduinoIDE i get the right response from the arduino, i run your program on the arduino for testing. I also cleared the variables in snap to see if it not just the old values.
Is there some way to reset the SerialPort/Webserver or clear it?
Asynchronous communication works that way. There is only a byte stream without any boundaries between "serial.write". On the receiving side, you can get 0 or many bytes, collected by the serial hardware buffer. To get the meaning of those bytes, you need to know, by any means, when the message is complete. You may use a timeout (say 200ms after the last byte received) or detect a designated message boundary marker ( say CR/LF).
Of course, received bytes should be returned only once.
us a determiened String...
But I really don't understand that part. Can you share a Snap project?
A few years ago library was extensively tested and I never found that problem.
I need more information to test against my boards.
What OS/browser do you use?
I think i used the wrong word, i meant a fixed String like Serial.write("AB") instead of Serial.write(Serial.read()). I thought determined mean the same, but maybe i'm mistaken.
I use Google Chrom, Version 129.0.6668.101 (Offizieller Build) (64-Bit)
The problem occurred after i used one of the following codes on the arduino side (working with Wemos D1 mini (clone)).
void setup() {
Serial.begin( 115200);
while (!Serial) {}
}
void loop() {
if (Serial.available()) {
Serial.print("#");
Serial.write("AB");
Serial.write("CD);
}
}
void setup() {
Serial.begin( 115200);
while (!Serial) {}
}
void loop() {
if (Serial.available()) {
Serial.print("#");
delay(1000);
Serial.write("AB");
delay(1000);
Serial.write("CD);
delay(1000);
}
}
It loops forever. To clear Serial.available()
you need Serial.read()
.