Serial doesn't work

Hello, I'm a teammate of Luke, and we are do this project together.

Honestly no, when we communicate by Serial without MKR all work. But when we use the MKR not work anymore.

We don't know, we found that on the forum and we try that.

We need to get all at the same GND so Arduino Uno that work 5V and MKR that work 3,3V so we have to transform the 5V into 3,3V or vice versa

Think about this: you're taking a 3.3V output and you're reducing its voltage before feeding it into an input on a 5V device.

Does that make any sense to you?

So we have to delete the circuit based on the diagram?

I'm trying to understand you, but I can't.
Using only Arduino Uno, and writing in serial work so no sense the stealer story.

as a side note [quote="Luke10105, post:19, topic:1249360"]

void loop() {
  Serial.println("starting WebSocket client");
  client.begin();

[/quote]

do you really need to begin() the client in every loop()?


it would be worth connecting to a software serial port so that you could debug easily

We not begin the client every loop or better, we begin every loop while the client hasn't connected to the socket. When the client is connected it join the while and so not repeat again the begin

PS: When we use connected with Serial Monitor, it ensures us that not try again the begin because not print "Starting websocket client"

well I see this at the start of the loop

Yeah but next join a while and from that while it not exit, like while true

until client gets disconnected and then the loop loops and you call begin() again

Regarding the schematic:
A schematic that does not reflect true components and wiring as as good as useless. Draw a true one with pen and paper, take a photo and attached it.

I can not find if anybody mentioned this but Serial.print on the MKR prints over the USB connection, not the Tx/Rx pins. Use Serial1 instead.

Right, in fact if the client is disconnected we have to begin or we haven't the bind with the socket

This is interestaring, so the pin TX and RX use Serial1 and not Serial right? Now we try something, but I have a question. Arduino Uno doesn't have Serial 1 so the Serial1 of MKR can communicate with Serial of Arduino Uno?

Yes.

Note that I specifically mentioned the MKR, not the Uno. So on the Uno you use Serial for communication over USB and over Tx/Rx and on the MKR you can use Serial1 for the communication over Tx/Rx and Serial for communication of USB.

Notes:

  1. Connecting something to the Tx and Rx pins on the Uno will interfere with the upload to the Uno. So you have to disconnect before uploading and reconnect afterwards. Alternatively you can use SoftwareSerial on two other pins for communication with the MKR during development and later use Serial. Advantage is that you maintain the ability to debug your Uno code using Serial.
  2. The Uno has one UART that is used for both USB and Tx/Rx. The MKR has several UARTs (one is connected to Tx/Rx) and uses native USB for communication with the PC.

We've just tried with Serial1, in both circuit so with the resistence and then connecting directly RX - TX between Uno and MKR. But in both case Uno not receive nothing from MKR.

How do you know?

Because if I write in serial using only Arduino, it moves the motor. But When we do that with MKR doesn't moves the motor

More than a question it's an affermation

Bro read and next do the affermation. You say that the problem is that two places in my code are consuming byte.
But when I use Serial Monitor it all works, so can you understand too that it can't be the problem? Because if it was the problem when we use the Serial Monitor it should not work, but it works with serial monitor

Bro I listen what you say, but I want that you tell me why with Serial Monitor work.
Because if I understand well that you say, the problem of "lost bytes" tecnically it should show up in Serial Monitor too, and not only when we use TX & RX

well

this is executed every time the loop() loops

and if you got a \n then the first thing you do in the loop is this

but then later on in the loop if distance is >= 100 you also do remove a byte from the Serial buffer by doing

So this is a problem because you can't predict what you read from within the loop and what you extract in the SerialEvent() function


So I'm curious to know how well you tested that to affirm that "when I use Serial Monitor it all works"

Yeah right, but we never use serialEvent function