Asked — Edited

Serial Communication With Arduino

Hey everyone,

I am using arduino's in my coding class, and have tried to communicate with it via the ez-b over serial. I seem to be able to receive, but I am not able to send it seems.

I am using the serial terminal for ez-b, as well as the serial monitor in the arduino ide. When I send a string, the ez-b recieves, but I cannot seem to get the arduino to recieve from the ez-b.

I was wondering if anyone who has been doing this can shed some light on it for me, as I am still trying to learn the ropes.

Arduino code:

#include 

Servo servo1; servo servo2; 


void setup() {

  pinMode(1,OUTPUT);
  servo1.attach(14); //analog pin 0
  //servo1.setMaximumPulse(2000);
  //servo1.setMinimumPulse(700);

  servo2.attach(15); //analog pin 1
  Serial.begin(9600);
  Serial.println("Ready");

}

void loop() {

  static int v = 0;

  if ( Serial.available()) {
    char ch = Serial.read();
    Serial.println("y");
    switch(ch) {
      case '0'...'9':
        v = v * 10 + ch - '0';
        break;
      case 's':
        servo1.write(v);
        v = 0;
        break;
      case 'w':
        servo2.write(v);
        v = 0;
        break;
      case 'd':
        servo2.detach();
        break;
      case 'a':
        servo2.attach(15);
        break;
    }
  }

} 

Thanks guys. Dylan


ARC Pro

Upgrade to ARC Pro

With Synthiam ARC Pro, you're not just programming a robot; you're shaping the future of automation, one innovative idea at a time.

PRO
USA
#1  

Quote:

as well as the serial monitor in the arduino ide.

Did you configured the serial monitor with no "line ending" window bottom right ?

#2  

I've tried multiple ways, might be worth a second shot.

PRO
Synthiam
#3  

You can click in the terminal window and type, rather than typing words and pressing send.

Are you sure the wire is connected to the correct port?

If it receives, it is sending. Check the wiring:)

Your code looks fine, although i'd add a DEFAULT for debugging...


void loop() {

  static int v = 0;

  if ( Serial.available()) {
    char ch = Serial.read();
    Serial.println("y");
    switch(ch) {
      case '0'...'9':
        v = v * 10 + ch - '0';
        break;
      case 's':
        servo1.write(v);
        v = 0;
        break;
      case 'w':
        servo2.write(v);
        v = 0;
        break;
      case 'd':
        servo2.detach();
        break;
      case 'a':
        servo2.attach(15);
        break;
      default:
       Serial.println(ch);
    }
  }


#4  

Only thing I don't have is a common Gnd, but if send works receive should work too, no?

PRO
USA
#5  

you need always a common ground even if you use full duplex lines.

bear in mind if you are using the same power source there is no need for a common ground.

I would say there is no reason not work...

"the devil is in the details"

Please provide more details:

  1. Are you using EZB or IoTiny ? EZB this one is simple:)
  2. Arduino model
  3. Wiring
  4. Arduino's Serial console print screen.
  5. ARC side print screen.
#6  

I will play with common ground, and the line ending. Will see if that fixes the issue. Otherwise I feel that it is most likely what I'm sending the arduino uno. Might not be in the correct form.

PRO
USA
#7  

Arduino Uno diagram: https://www.arduino.cc/en/uploads/Main/Arduino_Uno_Rev3-schematic.pdf

Uno has only one serial port: Pins 0 and 1 and is shared with another micro-controller (atmega16u2) to handle the USB communication.

When you connect to your arduino to monitor the communication the usb controller takes control over the serial port and if both pins are connected to the EZB you may have a problem.

You should use only the ARC serial monitor.

if you want to use the arduino usb/serial console or during arduino firmware uploads you need to disconnect any wires on pins 0 & 1, special the pin 0 (RX).

PRO
USA
#8  

If you need more than one serial port, it helps the debug process:

Arduino Uno:

use SoftwareSerial library to implement a software serial port: https://www.arduino.cc/en/Reference/softwareSerial and use those pins to communicate with EZB, keep the hardware serial for firmware uploads and debug serial console

Or use another arduino:

  1. Arduino Leonardo has 2, USB + 1

  2. Arduino Mega has 4: USB + 3

  3. Teensy 3.2 Cortex M4 (Supports Arduino Ide) has 3

#9  

Nice...the exact same thing is on my to do list! Good to see that I will be having a thread to look up if I am running into any issues!:)

#10  

Hi...i am a new user here. As per my knowledge you should go for a common ground even if you use full duplex lines. Also if you are using the same power source there is no need for a common ground.

surface mount assembly

#11  

Hi, I am new in RObotics, and much interested in buying EZ-B Wi Fi robot controller. I have also faced difficulties in serial communication of Arduino with other boards. So if EZ-B has USB port, it will very easy to send data to USB over serial communication, we just need to send the data using Serial.println and nothing else. So does EX-b has USB port?

void loop()                                           // execute the loop forever
{
  if(digitalRead(2)==LOW)                 // if button attached to the UNO is pressed
    {
     digitalWrite(3,HIGH);                         // turn ON the LED at PIN3
     Serial.println( "ButtonPressed" );        // send "ButtonPressed" string of characters serially out
     delay(200);                                           // wait for 200 milli second
     digitalWrite(3,LOW);                          // turn OFF the LED
    }
}

Source: arduino raspberry pi communication like arduino communicate with Raspberry pi

So please let me know if EZ-B has USB port?