Serial Communication With Arduino

 
#1

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:

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

#2

Quote:


as well as the serial monitor in the arduino ide.



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

#3

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

#4

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 Smile

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

Code:


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);
}
}

#5

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

#6

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 Smile
2) Arduino model
3) Wiring
4) Arduino's Serial console print screen.
5) EZBuilder side print screen.

#7

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.

#8

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 EZ-Builder 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).

#9

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

#10

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! Smile