SMALL - espritmodel.com SMALL - Telemetry SMALL - Radio
Reply
Thread Tools
Old Feb 15, 2013, 09:42 AM
Registered User
tweety777's Avatar
Vlaardingen, The Netherlands
Joined Nov 2008
1,338 Posts
Hi Pete,

Thanks for the advice.

I think these wouldn't be all that good for transmitting video signals due to the low frequency.
For controlling the boat I already have 2 2,4GHz transceivers.
For forwarding commands to the lifeboats I'll be using the short range version of the same transceiver which is smaller and thus more useful for the tiny lifeboats.

Greetings Josse
tweety777 is offline Find More Posts by tweety777
Reply With Quote
Sign up now
to remove ads between posts
Old Feb 18, 2013, 01:04 AM
Registered User
tweety777's Avatar
Vlaardingen, The Netherlands
Joined Nov 2008
1,338 Posts
I thought it would be nice for you guys to know which Arduinos I'm using.
At this point I have 1 Arduino Uno in the stern (up and running), about to be replaced by a Mega, all other computers will be Megas as well, the communication Arduino is here already.

Today I'll try to write some code for the communication Arduino so it will receive data from the USB cable and pass that through to the stern Arduino.
When I have received my order (containing 3 Arduino Megas) I'll re-wire the puls wire for the bow thruster and connect that to the new bow computer.

At this point my software will only send data when the status of something is changed, so when I don't click any button or move any trackbar no data will be send.
Thus I keep the line as clean as possible.
When I get to the point of sending data wireless I'll see whether or not I will have the boat reply to check for wrong received data.

Greetings Josse
tweety777 is offline Find More Posts by tweety777
Reply With Quote
Old Feb 18, 2013, 02:54 AM
Registered User
tweety777's Avatar
Vlaardingen, The Netherlands
Joined Nov 2008
1,338 Posts
Today I tried to write some code for controlling the boat from the communication Arduino.
It seemed simple enough but turned out not to be that simple so I'm stuck now.
The com Arduino is receiving the orders from the laptop but the receiving Arduino doesn't show any signs of a received message at all.
Just to be sure I'm forwarding to the correct wires I decided to write the code such that it is forwarding to all serials.
For some reason this still doesn't help at all.
Then I decided to take a look at the code for the executing Arduino and that gives me the feeling that when it would receive anything at all it still wouldn't do what it should do...
Here's the code I'm using now:
Comm:


#include <Servo.h>
//#include <RF24Network.h> //Uncomment when radio needs to be used
//#include <RF24.h> //Uncomment when radio needs to be used
//#include <SPI.h> //Uncomment when radio needs to be used

//int channel = 80; // what channel are we on? // comment for dynamic channel control //Uncomment when radio needs to be used
//int channelold; //Uncomment when radio needs to be used
//char buffer[64]; //Uncomment when radio needs to be used
//char msg[140] = ""; //Uncomment when radio needs to be used


// let's define some servo's
Servo servo1; Servo servo2; Servo servo3; Servo servo4;
Servo servo5; Servo servo6; Servo servo7; Servo servo8;
Servo servo9; Servo servo10; Servo servo11; Servo servo12;
// minimum and maximum range for the servo
int servmin1 = 0; int servmax1 = 255;
int servmin2 = 0; int servmax2 = 255;
int servmin3 = 0; int servmax3 = 255;
int servmin4 = 0; int servmax4 = 255;
int servmin5 = 0; int servmax5 = 255;
int servmin6 = 0; int servmax6 = 255;
int servmin7 = 0; int servmax7 = 255;
int servmin8 = 0; int servmax8 = 255;
int servmin9 = 0; int servmax9 = 255;
int servmin10 = 0; int servmax10 = 255;
int servmin11 = 0; int servmax11 = 255;
int servmin12 = 0; int servmax12 = 255;


int pinNumber; int pinValue;
int Pin22 = 22; int Pin23 = 23; int Pin24 = 24; int Pin25 = 25;
int Pin26 = 26; int Pin27 = 27; int Pin28 = 28; int Pin29 = 29;
int Pin30 = 30; int Pin31 = 31; int Pin32 = 32; int Pin33 = 33;
int Pin34 = 34; int Pin35 = 35; int Pin36 = 36; int Pin37 = 37;
int Pin38 = 38; int Pin39 = 39; int Pin40 = 40; int Pin41 = 41;
int Pin42 = 42; int Pin43 = 43; int Pin44 = 44; int Pin45 = 45;
int Pin46 = 46; int Pin47 = 47; int Pin48 = 48; int Pin49 = 49;
int Pin53 = 53; int Pin8 = A0; int Pin9 = A1; int Pin10 = A2;
int Pin11 = A3; int Pin12 = A4; int Pin13 = A5;
int Pin14 = A6; int Pin15 = A7;

// nRF24L01(+) radio attached to SPI and pins 8 & 9
//RF24 radio(8,9); //Uncomment when radio needs to be used

// Network uses that radio
//RF24Network network(radio); //Uncomment when radio needs to be used

// Address of our node
//const uint16_t this_node = 0; // the receiver code //Uncomment when radio needs to be used

// Address of the other node
//const uint16_t other_node = 1; // the transmittercode //Uncomment when radio needs to be used

void setup() {
Serial.begin(115200);
Serial1.begin(115200);
Serial2.begin(115200);
Serial3.begin(115200);
}

void loop() {
if (Serial.available()) {
int inByte = Serial.read();
delay(20);
Serial3.print (inByte);
Serial2.print (inByte);
Serial1.print (inByte);
}
}

I commented the parts that use the radio as I'd first need to get this working without the radio.
Otherwise I would now likely be checking out whether or not the radio works fine whilst the problem clearly isn't the radio...

Then the executing Arduinos code:

// Added Arduino libraries
#include <Servo.h>

//define all functions and variables
char buffer[64];
int ServoA = 11; int ServoB = 10; int ServoC = 9; int ServoD = 6; int ServoE = 5; int ServoF = 3; int counter = 0;
Servo servoa; Servo servob; Servo servoc; Servo servod; Servo servoe; Servo servof; Servo servoh;
//maximum and minimum values for the servos
int servamin = 0; int servamax = 255;
int servbmin = 0; int servbmax = 255;
int servcmin = 0; int servcmax = 255;
int servdmin = 0; int servdmax = 255;
int servemin = 0; int servemax = 255;
int servfmin = 0; int servfmax = 255;
int servhmin = 0; int servhmax = 255;

#define DEBUG

//temporary def
int analogValue5, val5;
char msg[140] = "";
int var5old = 0;

void midden(){
servoa.write(120); servob.write(120); servoc.write(120); servod.write(120); servoe.write(120); servof.write(120); //servo midpoint
digitalWrite(13, LOW); digitalWrite(12, LOW); digitalWrite(8, LOW); digitalWrite(7, LOW); digitalWrite(4, LOW); digitalWrite(2, LOW); //LEDS off
}

void setup()
//Setup for communication
{
Serial.begin(115200);
delay(20);
Serial.flush();

//servo setup and naming
//the digital ports
servoa.attach(11); servob.attach(10); servoc.attach(9); servod.attach(6); servoe.attach(5); servof.attach(3);
pinMode(ServoA, OUTPUT); pinMode(ServoB, OUTPUT); pinMode(ServoC, OUTPUT); pinMode(ServoD, OUTPUT); pinMode(ServoE, OUTPUT); pinMode(ServoF, OUTPUT);
pinMode(13, OUTPUT); pinMode(12, OUTPUT); pinMode(8, OUTPUT); pinMode(7, OUTPUT); pinMode(4, OUTPUT); pinMode(2, OUTPUT);
midden();
}

//Start reading the input value
void loop()
{

if (Serial.available() > 0) {
int index=0;
delay(10); // let the buffer fill up
int numChar = Serial.available();
if (numChar>64) {
numChar=64;
}
while (numChar--) {
buffer[index++] = Serial.read();
}
splitString(buffer);
}
}
void splitString(char* data) {
Serial.print("Data entered: ");
Serial.println(data);
char* parameter;
parameter = strtok (data, " ,");
while (parameter != NULL) {
setLED(parameter);
parameter = strtok (NULL, " ,");
}
// Clear the text and serial buffers
for (int x=0; x<64; x++) {
buffer[x]='\0';
}
Serial.flush();
}

// initialise function. Just type i and all will go 0 and midpoint
void setLED(char* data) {
if ((data[0] == 'i') || (data[0] == 'I')) {
midden();
}

//The servos are now taken out of the buffer
//SERVO A
if ((data[0] == 'a') || (data[0] == 'A')) {
int serva = strtol(data+1, NULL, 10);
serva = constrain(serva,servamin,servamax);
servoa.write(serva);
#ifdef DEBUG
Serial.print("ServoA is set to: ");
Serial.println(serva);
#endif
}

//SERVO B
if ((data[0] == 'b') || (data[0] == 'B')) {
int servb = strtol(data+1, NULL, 10);
servb = constrain(servb,servbmin,servbmax);
servob.write(servb);
#ifdef DEBUG
Serial.print("ServoB is set to: ");
Serial.println(servb);
#endif
}

//SERVO C
if ((data[0] == 'c') || (data[0] == 'C')) {
int servc = strtol(data+1, NULL, 10);
servc = constrain(servc,servcmin,servcmax);
servoc.write(servc);
#ifdef DEBUG
Serial.print("ServoC is set to: ");
Serial.println(servc);
#endif
}

//SERVO D
if ((data[0] == 'd') || (data[0] == 'D')) {
int servd = strtol(data+1, NULL, 10);
servd = constrain(servd,servdmin,servdmax);
servod.write(servd);
#ifdef DEBUG
Serial.print("ServoD is set to: ");
Serial.println(servd);
#endif
}

//SERVO E
if ((data[0] == 'e') || (data[0] == 'E')) {
int serve = strtol(data+1, NULL, 10);
serve = constrain(serve,servemin,servemax);
servoe.write(serve);
#ifdef DEBUG
Serial.print("ServoE is set to: ");
Serial.println(serve);
#endif
}

//SERVO F
if ((data[0] == 'f') || (data[0] == 'F')) {
int servf = strtol(data+1, NULL, 10);
servf = constrain(servf,servfmin,servfmax);
servof.write(servf);
#ifdef DEBUG
Serial.print("ServoF is set to: ");
Serial.println(servf);
#endif
}

//SERVO F
if ((data[0] == 'h') || (data[0] == 'h')) {
int servh = strtol(data+1, NULL, 10);
servh = constrain(servh,servhmin,servhmax);
servoa.write(servh);delay(100);
servob.write(servh);
#ifdef DEBUG
Serial.print("ServoTotal is set to: ");
Serial.println(servh);
#endif
}

// start function LED

if ((data[0] == 'g') || (data[0] == 'G')) {
int ledcode = strtol(data+1, NULL, 10);
Serial.print(counter);
if (ledcode >= 32) {
digitalWrite(13, HIGH);
ledcode = (ledcode - 32); }
else
{
digitalWrite(13, LOW);
}
if (ledcode >= 16) {
digitalWrite(12, HIGH);
ledcode = (ledcode - 16); }
else
{
digitalWrite(12, LOW);
}
if (ledcode >= 8) {
digitalWrite(8, HIGH);
ledcode = (ledcode - 8); }
else
{
digitalWrite(8, LOW);
}
if (ledcode >= 4) {
digitalWrite(7, HIGH);
ledcode = (ledcode - 4); }
else
{
digitalWrite(7, LOW);
}
if (ledcode >= 2) {
digitalWrite(4, HIGH);
ledcode = (ledcode - 2); }
else
{
digitalWrite(4, LOW);
}
if (ledcode >= 1) {
digitalWrite(2, HIGH);
ledcode = (ledcode - 1); }
else
{
digitalWrite(2, LOW);
}

} }

Hopefully this makes sense...

Greetings Josse
tweety777 is offline Find More Posts by tweety777
Reply With Quote
Old Feb 18, 2013, 06:08 AM
Registered User
tweety777's Avatar
Vlaardingen, The Netherlands
Joined Nov 2008
1,338 Posts
I have located the problem but I'm not yet able to solve the problem.
At some point I realised that only the RX LED was flashing which means that no data was passed through to the other Arduino.
After some searching I discovered that I hadn't told the Arduino what it should be sending and then it automatically returns to 0 before having send any message.
I now also know that when the Arduino reads it's serial line it stores the received data in it's buffer.
What I need to do is find the command that will tell the Arduino to print whatever gets written in the buffer and then flush the lot so a new command can be received and passed through.
It would seem that when I managed to get that done I'll have a working system, if not, then I'll need to re-write the program for the stern computer as well as that then probably doesn't know what the received code means or what it should do with it.

Greetings Josse
tweety777 is offline Find More Posts by tweety777
Reply With Quote
Old Feb 18, 2013, 08:55 AM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
296 Posts
Josse,
Since I know a little about the code you use I try to explain. The RX/TX leds are only for the RX/TX 0. serial 1-3 have no leds. Also I can not find anything you send to other arduino's. I see that you try to send all the data that comes in to the main arduino to the slave units. I also see 2 void loop() and 2 void setup() with a redefinition of serial speed. Perhaps it's better to get the program organized first. Don't send all commands to all arduino's. Just the commands that you need. For example:

//SERVO A
if ((data[0] == 'a') || (data[0] == 'A')) {
Serial.write1(data); // this is the slave unit
}

the receiving slave arduino has to read the command from the serial and convert it to the corresponding servo.

Good luck,

Danny
Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Old Feb 18, 2013, 09:02 AM
Registered User
tweety777's Avatar
Vlaardingen, The Netherlands
Joined Nov 2008
1,338 Posts
Hi Danny,

Your reading 2 different codes, 1 for the comm Arduino, 1 for the executing Arduino, that's why there are 2 void setups and 2 void loops.

At this point I decided to simply send anything to 1 other Arduino as the comm Arduino is only handling the communication and there is only 1 Arduino attached.
Therefore it is at this point easier and yet effective to send everything away.
At this point I'm only trying to establish an connection between the 2 Arduinos, splitting the commands will come later.

Greetings Josse
tweety777 is offline Find More Posts by tweety777
Reply With Quote
Old Feb 18, 2013, 09:10 AM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
296 Posts
The main receiving arduino that is attached to your computer. Which type is it. The Serial commands are for a Mega with 4 serials. As I recollect you have a Uno or did you allready buy the Mega? It is possible to work woth an uno but you have to use softserial. Try the wire examples first so you know what you're doing.

Danny
Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Old Feb 18, 2013, 09:15 AM
Registered User
tweety777's Avatar
Vlaardingen, The Netherlands
Joined Nov 2008
1,338 Posts
Hi Danny,

I have 1 Arduino Mega 1280 as comm Arduino for quite some time now and the Uno is the stern computer though that is about to be replaced by a Mega when the postal services finally deliver my shipment.
When that shipment arrives I'll have all Arduinos I need for this boat, leaving me with a surplus Nano and Uno.
The surplus Nano might well be used to connect the future tablet to it's to be ordered 2,4GHz transceiver (I want a new unit for the tablet so I don't need to take the instrument panel apart when I want to test the new system using my laptop which will remain being 1 stage prior to the final stage in the development stage).

Greetings Josse
tweety777 is offline Find More Posts by tweety777
Reply With Quote
Old Feb 18, 2013, 01:17 PM
Registered User
tweety777's Avatar
Vlaardingen, The Netherlands
Joined Nov 2008
1,338 Posts
Last week I decided it would be useful to think of a standard way to connect all the electronics.
Therefore I made a document (in Dutch off course...) so I could check how I want to set the wiring and electronics up.
Here's my plan:

A command will be send from the laptop or the tablet (which is to be placed in an instrument panel in such a way that it's screen is still usable).
The communication Arduino receives the command and passes it through the executing Arduino (for some functions, like the propulsion of the smaller craft, the comm Arduino is the executing Arduino).
The executing Arduino executes the command.
Depending on the device connected to the function either a servo or ESC is notified of it's new status, which is the end of this line.
If the device is an ON/OFF function chances are it takes too much power to be powered by the Arduino itself so in that case the Arduino will send power to a relay which will then turn the function on or off.
As the Arduino can only handle 20mAmps per pin I've chosen to connect every function that has more then 1 LED to it's own power source, meaning that pretty much everything will be turned ON and OFF by means of a relay.

Greetings Josse
tweety777 is offline Find More Posts by tweety777
Reply With Quote
Old Feb 18, 2013, 09:55 PM
Registered User
Deckie's Avatar
Australia, WA, Garden Island
Joined Nov 2010
464 Posts
Tweety, I strongly reccomend you use i2c to connect the arduinos to each other. The wire library is simple to use, and you only need two physical lines, sca and sdl which are clock and data respectively. I have tested over two Meters with no corruption problems.
Deckie is offline Find More Posts by Deckie
Reply With Quote
Old Feb 19, 2013, 02:02 AM
Registered User
tweety777's Avatar
Vlaardingen, The Netherlands
Joined Nov 2008
1,338 Posts
Hi Deckie,

Thanks for the advice.
Using the RX and TX pins also takes only 2 wires between 2 Arduinos and this method should be easier to use as all Arduino needs to know is that you want to send something on the serial line, that line is by default through the RX and TX pins.
I have found some youtube movies that mention the I2C method so I guess your not the only 1 who has tried it.
The only problem with this method is that the Uno has no dedicated SDA and SCL pins so I'd better wait till the new Megas arrive.
Then there's the point of that the Mega also has only 1 SDA and 1 SCL pin and I'm going to have 3 Arduinos connected.
Still, I don't see any reason for not trying this method.

Greetings Josse
tweety777 is offline Find More Posts by tweety777
Reply With Quote
Old Feb 19, 2013, 04:02 AM
Registered User
Deckie's Avatar
Australia, WA, Garden Island
Joined Nov 2010
464 Posts
Quote:
Originally Posted by tweety777 View Post
Hi Deckie,

Then there's the point of that the Mega also has only 1 SDA and 1 SCL pin and I'm going to have 3 Arduinos connected.
Still, I don't see any reason for not trying this method.

Greetings Josse
Josse, I hate to say this, but you are incorrect

Yes it has one set of pins, however multiple arduinos may use the one set of wires, you simply have to give each Arduino it's own address, check the examples in the Arduino IDE even fact, even sensors may share the same bus, as long as you give them an address, this is precisely why Phillips developed it

The one thing that must happen, as you can see in the diagram is that all devices using the bus must share a common ground/ source of power.
Deckie is offline Find More Posts by Deckie
Reply With Quote
Old Feb 19, 2013, 04:25 AM
Registered User
tweety777's Avatar
Vlaardingen, The Netherlands
Joined Nov 2008
1,338 Posts
Hi Deckie,

In that case I'll see if I can get this method to work properly.
I'm hoping to be able to control the boat wireless from my laptop before 6 april as that is the first sailing day at the club.

Greetings Josse
tweety777 is offline Find More Posts by tweety777
Reply With Quote
Old Feb 19, 2013, 05:32 AM
Registered User
Deckie's Avatar
Australia, WA, Garden Island
Joined Nov 2010
464 Posts
Quote:
Originally Posted by tweety777 View Post
Hi Deckie,

In that case I'll see if I can get this method to work properly.
I'm hoping to be able to control the boat wireless from my laptop before 6 april as that is the first sailing day at the club.

Greetings Josse
Where there is a will, there is a solution. I reckon you'll get there
Deckie is offline Find More Posts by Deckie
Reply With Quote
Old Feb 19, 2013, 05:34 AM
Registered User
tweety777's Avatar
Vlaardingen, The Netherlands
Joined Nov 2008
1,338 Posts
Hi Deckie,

You got a point there, now let's hope I get some more energy to keep working at some pace...

Greetings Josse
tweety777 is offline Find More Posts by tweety777
Reply With Quote
Reply


Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Discussion KK Plus 5.5d/e Best value Enhanced KK Controller And MEMS/ACC Module dt8666 Multirotor Electronics 3396 Aug 27, 2014 12:07 PM
Build Log Diving supportvessel Well Enhancer 1:75 tweety777 Scale Boats 1659 Aug 27, 2014 11:41 AM
Discussion High Tech High Senior Project - Looking for Help & Suggestions! hth.uav Electric Plane Talk 13 May 16, 2012 07:32 AM
Discussion General rules for control surfaces ratios for aircraft? As well as CG's? GreenAce92 3D Flying 27 Feb 07, 2010 02:15 PM
My obscenely low tech, yet somehow high tech, camera mount eBird Aerial Photography 29 Dec 31, 2004 06:49 PM