Hobbyking IOS & Android 4CH WiFi Receiver & Win Forms Csharp TX to Arduino RX

 

C# TX and Arduino RX for Coroplast Catamaran which will be self guiding with 2 GPS's one in the boat and one in the remote forming a virtual tether so the model can follow a full scale boat and still allow the operator to take control

900mm Black cat in Coroplast 6 hours to build hull 1.2Kgs Outboard ...

900mm Black cat in Coroplast 6 hours to build hull 1.2Kgs Outboard 380 Watts 3300kv from 70mm EDF 
 
 
Started off with this device after a long hiatus from the project due to other projects
 
and it made me thing of a simple system, only took 4 hours to code the UI and an hour for the Arduino programming
 
I'm using this device for the comms
 
 
 
The above are available from Hobby King for $29
This is my GPS Code it decodes the following NMEA83  messages

GSA, RMC, GAA 


Its built for the Netduino Plus but will work with other Neduinos and the Fez Panda II.

It users Async comms shown below, and rises an event for each packet.


        void com_DataReceived(object Sender, SerialDataReceivedEventArgs e)
        {
            NMEAdata data = ExtractPackets(com);
            
            if (data.UTCfixTaken != null)
                OnGPSmessage(data);
            
        }

My GPS is a few years old and came from http://www.parallax.com/ in 2008 it has 2 modes one for the Parallax BS2 and a jumper selected mode where is sends NMEA packets continuously. 

Please feel free to download the code here 
Here is the Arduino RX code

#include <Servo.h>

String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
int com_state = 0;
int PackCount = 0;
char Packet[11] = {0, };

long Cooling = 0;
long PumpSpeed = 0;

Servo Servo1;
Servo Servo2;
Servo Servo3;
Servo Servo4;

#define MAX_CHAN 8
int AnIn[MAX_CHAN] = {0, };

unsigned long PPMtout = 20000;

char buf[300] = {0, };

long mS = 0;

void setup() {

pinMode(13, OUTPUT);

Serial.begin(115200);

// reserve 200 bytes for the inputString:
inputString.reserve(200);

Servo1.attach(8);
Servo2.attach(9);
Servo3.attach(10);
Servo4.attach(11);

}

void loop() {

AnIn[0] = analogRead(A0);
AnIn[1] = analogRead(A1);
AnIn[2] = analogRead(A2);
AnIn[3] = analogRead(A3);
AnIn[4] = analogRead(A4);
AnIn[5] = analogRead(A5);
AnIn[6] = analogRead(A6);
AnIn[7] = analogRead(A7);

/* RAZU-2 Six turn
This device has a gain of 55mV per amp giving a 36 Amp working range,
and a resolution of 11.3777 mA per bit with the maximum output at 5 volts
which is 1024 bits in the Arduino. By the way I should point out that
these devices on a 5 volt rail will sit around 2.5 volts with no current
flowing, so at a 2 Volt delta the out put should be around 4.5 V
*/

mS = micros();

//Calc amps
long Amps = (long)map((AnIn[1] - 512), 0, 512, 0, 36);

//Calculate cooling temp RTC on AnIn[0]
int cerr = ((int)600 - (int)AnIn[0]);

//Integrate temparature
Cooling += cerr;

if(Cooling < 1000) Cooling = 1000;
else if(Cooling > 2000) Cooling = 2000;

//Use the temperature integrator plus the motor current
//36 Amps gives us 360 bits
PumpSpeed = (long)Cooling + (Amps * 10);

//Update the outputs

Servo1.writeMicroseconds((int)PumpSpeed);

long Cyc_mS = (micros() - mS);

// print the string when a newline arrives:
if (stringComplete) {

//Servo2.writeMicroseconds((int)Packet[4]);
Servo2.write((int)Packet[5]);

sprintf(buf, "AnIn[0]:%d,AnIn[1]:%d,CoolingError:%d,Cooling:%d,MotorAmps:%d,Cyc_mS:%d", AnIn[0], AnIn[1], cerr, (int)Cooling, (int)Amps, (int)Cyc_mS );

Serial.println(buf);

stringComplete = false;
}

//ALLOW SERVOS TO UPDATE
delayMicroseconds(20000);

Cyc_mS = (micros() - mS);

}

/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent() {

while (Serial.available()) {

// get the new byte:
byte inChar = (byte)Serial.read();

switch(com_state)
{
case 0:

digitalWrite(13, HIGH);

if(inChar == 85){
Packet[0] = inChar;
PackCount = 1;
com_state = 1;
}
break;

case 1:

if(PackCount < 11)
Packet[PackCount++] = inChar;
else
{
PackCount = 0;

int sum = 0;
for (int i = 0; i < 9; i++)
sum += (int)Packet[i];

byte Chk = (byte)(sum % 256);

//sprintf(buf, "LC=%d\nRC=%d", (int)Chk, (int)Packet[10] );

//Serial.println(buf);

if(Chk == Packet[10])
{
digitalWrite(13, LOW);
stringComplete = true;
com_state = 0;

}
}
break;
}

}
}

Views: 3943


Moderator
Comment by Gary Mortimer on October 25, 2013 at 2:31am

Beware the USB noise on clone 433 radios, unless they have fixed them now. 

Comment by Ace on October 25, 2013 at 3:23am

No, they didn't. I ordered one and it was useless. Maybe because my laptop is RF noisy

Comment by Nick Goodey on October 25, 2013 at 1:57pm

I found it liked to be at least a meter away from the laptop to work reliably 

Comment by Nick Goodey on October 25, 2013 at 1:57pm

Any way roll your own with an Arduino and a WiFi shield 

Comment by Jesse on October 25, 2013 at 11:24pm

I love C#, very user friendly for Window apps!

Comment by Nick Goodey on October 25, 2013 at 11:42pm

I do too use it a lot at work. You can use VS 2010 C# on the Netduino/FEZ Panda with Micro CLR but its not real-time I tried to use Netduino a while back so now I use Arduino  for my projects. I will have the TX running on Arduino soon hopefully 

Comment

You need to be a member of DIY Drones to add comments!

Join DIY Drones

Groups

Season Two of the Trust Time Trial (T3) Contest 
A list of all T3 contests is here. The current round, the Vertical Horizontal one, is here

© 2019   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service