RS485 and controlling a motor.


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 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()
  //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
  //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

  //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;
    if (Up.getValue() > 0){
    else if (Dwn.getValue() > 0){
    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;

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.


I'm trying to send a similar packet of data between two arduinos using the RS485 protocol.

Where is your code for receiving the data? Sending the data, whatever it is, would simply be the reverse process of reading it.

Sending a packet start marker without an end of packet marker is like this sentence

You never know where it is going to end.

Have a look at the examples in serial input basics. The 3rd one would be best. Then design your sending program to match.


RS485 isn't really a protocol, its the physical layer specification for differential
signalling on UTP. Normally you build a packet protocol on top of it, often using
standard serial comms. RS485 allows multiple transceivers on a terminated bus,
but says nothing about negotiating bus master status. For unidirectional use its
basically a souped up robustified serial connection with higher bandwidth possible.

If you want bidirectional signalling you have to worry about contention, you don't
get any help (not even collision detection) from RS485. Simple request/response
behaviour is commonly employed with one node only initiating communications.