DuxDucis
USA
Asked
— Edited
Hey there, I recently got myself an arduino uno for embedded programming, but it lacks the amount of IO pins the EZ-B has, then I thought to myself, why not control the ezb from the arduino? So here, I've ported a minimal part of Openbot to arduino to control servos and set digital ports for now. To make this work you connect the pin 5 in your arduino to the rx pin in the EZB with a jumper cable and pin 6 in your arduino to the tx pin in EZB and voila. I've made a quick example here that uses 2 servos and turns on some leds. Be aware that the class itself does not require the Arduino Timer library, but my sketch does, so here it is.
Tell me what you think
#include toneAC.h
#define SERVO_CENTER 70
#define SERVO_MAX 40
#define SERVO_MIN 1
#define SERVO_OFF 0
#define SERVO_SPEED_FASTEST 0
#define SERVO_SPEED_SLOWEST 10
#include
#include Event.h
#include Timer.h
class EzRobot{
SoftwareSerial EzRobotConnection;
public:
void KeepAlive();
void RunSetup();
EzRobot();
EzRobot(byte rx, byte tx);
void SetServoPosition(byte ServoPort, byte servo_set_pos);
void SetDigitalPort(byte ServoPort, bool active);
void PlayTone(byte SpeakerPort, byte note, byte noteLength);
};
void EzRobot::KeepAlive(){
EzRobotConnection.write(85);
}
EzRobot::EzRobot(){
}
void EzRobot::RunSetup(){
}
EzRobot::EzRobot(byte rx, byte tx) {
Serial.println("LODS");
EzRobotConnection = SoftwareSerial(rx,tx);
EzRobotConnection.begin(9600);
EzRobotConnection.write(85);
EzRobotConnection.flush();
}
void EzRobot::SetDigitalPort(byte ServoPort, bool active){
if (active){
EzRobotConnection.write(100 + ServoPort);
}
else{
EzRobotConnection.write(120 + ServoPort);
}
}
void EzRobot::SetServoPosition(byte ServoPort, byte servo_set_pos){
if (servo_set_pos > 180){
servo_set_pos = 180;
}
else if(servo_set_pos < 0){
servo_set_pos = 0;
}
byte data[2];
data[0] = 160 + ServoPort;
data[1] = servo_set_pos;
EzRobotConnection.write(data, 2);
}
EzRobot EZB;
Timer EZBKeepAlive;
Timer PlayRandomNote;
Timer ServoMove;
bool forward = true;
bool stopped = true;
bool FirstPingSent = false;
bool SecondPingSent = false;
bool lightsOn = false;
byte note = 0;
void setup(){
toneAC();
Serial.begin(9600);
EZB = EzRobot(5,6);
EZBKeepAlive.every(1000, KeepEZBAlive);
PlayRandomNote.every(250, RandomNote);
PlayRandomNote.every(2000, ServoMoveFunc);
delay(3000);
EZB.RunSetup();
}
void ServoMoveFunc(){
if (!lightsOn){
EZB.SetDigitalPort(2, true);
EZB.SetDigitalPort(3, true);
EZB.SetDigitalPort(4, true);
lightsOn = true;
}
else{
EZB.SetDigitalPort(2, false);
EZB.SetDigitalPort(3, false);
EZB.SetDigitalPort(4, false);
lightsOn = false;
}
if (stopped){
if (forward){
EZB.SetServoPosition(0, 1);
EZB.SetServoPosition(1, 180);
}
else{
EZB.SetServoPosition(0, 180);
EZB.SetServoPosition(1, 1);
}
forward = !forward;
stopped = false;
}
else{
EZB.SetServoPosition(0, 0);
EZB.SetServoPosition(1, 0);
stopped = true;
}
}
void RandomNote(){
toneAC(random(100, 4000), 10, 250, true);
}
void KeepEZBAlive(){
EZB.KeepAlive();
}
void loop(){
Serial.println("TESTING");
EZBKeepAlive.update();
PlayRandomNote.update();
}
WOW very cool was hopping for a interface from arduino to EZB
I know many others looking for a ezb to arduino,i made a spectrometer design using arduino board and was trying to find someone with a way to port it to EZB I KNOW VERY LITTLE ABOUT PROGRAMMING .
So, you want to control your Arduino from EZB? That's even easier, send me an email if you want some help. thomaspaniagua@gmail.com
ok will find the code for it,was made by another person i am electronics designer by trade,and mostly know everything about sensors and how to use them. and have almost every sensor made too. plus been building robots for a very long time