Hello,
I'm currently trying to figure out how to send a packet of data through the SoftwareSerial.h library.
I have sample code for turning on an LED but I'm looking to do something a little more involved, like controlling 6 brushless motors. I have done this once before using processing and my laptop as the "master". I'm trying to eliminate the laptop.
import procontroll.*;
import java.io.*;
import processing.serial.*;
//Create instances of specific hardware components;
ControllIO controll;
ControllDevice device;
ControllStick stick1;
ControllStick stick2;
ControllButton L2;
ControllButton R2;
ControllButton Up;
ControllButton Dwn;
ControllButton L1;
ControllButton R1;
//Create Serial port Instance
Serial port;
//Global Variable Callout:
byte y_left;
byte y_right;
byte crab_l;
byte crab_r;
byte VertCount;
byte manip_position;
float Count = 30;
int mposition = 90;
char PacketStart = '~'; //sgnifies the start of data packet
void setup()
{
size(100,100);
//Open a Serial port with device 0 at the defined speed;
port = new Serial(this, "COM4", 9600);
// Instantiate input/output capabilities;
controll = ControllIO.getInstance(this);
//lock onto the Controller
device = controll.getDevice("MotioninJoy Virtual Game Controller");
//recover the name of the controller from the printDevice() command
device.printSticks();
device.printButtons();
//Assigning variable names to both PS3 sticks:
stick1 = device.getStick("X axis Y axis");
stick2 = device.getStick("Y Rotation Z Rotation");
L2 = device.getButton("L1");
R2 = device.getButton("R1");
Up = device.getButton("Button 13");
Dwn = device.getButton("Button 15");
L1 = device.getButton("L2");
R1 = device.getButton("R2");
//Tolerances to tilt on joysticks before it registers
stick1.setTolerance(0.10f);
stick2.setTolerance(0.10f);
//Drawing Settings
// fill(0);
// rectMode(CENTER);
}
void draw()
{
// background(255);
//Grab both stick Y-Values
y_left = (byte) map(stick1.getY(), 1, -1, 0, 201) ;
y_right = (byte) map(stick2.getX(), 1, -1, 0, 201) ;
crab_l = (byte) map(L2.getValue(), 0, 8, 0, 1);
crab_r = (byte) map(R2.getValue(), 0, 8, 0, 1);
VertCount = (byte) constrain(Count,0, 60);
manip_position = (byte) mposition;
delay(75);
if (Up.getValue() > 0){
Count++;
}
else if (Dwn.getValue() > 0){
Count--;
}
if (R1.getValue() > 0){
mposition = mposition +5;}
else if (L1.getValue() > 0){
mposition = mposition - 5;}
//for debugging:
// print(y_left);
// print(" ");
// print(y_right);
// print(" ");
// print(crab_l);
// print(" ");
// print(crab_r);
// print(" ");
// print(VertCount);
// print(" ");
// println(manip_position);
//Send over the Serial Data;
port.write(PacketStart);
port.write(y_left);
port.write(y_right);
port.write(crab_l);
port.write(crab_r);
port.write(VertCount);
port.write(manip_position);
this is what I had in processing, it worked, albeit a bit haphazardly. I'm trying to send a similar packet of data between two arduinos using the RS485 protocol.
I'm looking for the rosetta stone between the two.
Thanks,
Branden