Hi,
I have built a camera slider (working) with the following basic setup:
-Stepper motor driving belt,
-uStepperS motor driver/ micro controller
-HC06 bluetooth connected to uStepperS
-MIT AI2 built app sending 1 byte information in array with a start end byte eg. StartByte, 1byte, 1byte, EndByte
- serial data is mapped in arduino code and fed to stepper motor
It struck me as more efficient to send the 2byte actual values, from the app.
E.g. send 2byte "1500" steps rather than a 1byte 253 value that is mapped 0-253 to 0-1500 in code on the uStepperS
Currently I am using the following to get serial
Code from "Little French Kev" 'nerf cannon'
byte byte_from_app;
const byte buffSize = 30;
byte inputBuffer[buffSize];
const byte startMarker = 255;
const byte endMarker = 254;
byte bytesRecvd = 0;
Void setup()
Void loop(
getDataFromPC();
)
void getDataFromPC() {
//expected structure of data [start byte, run byte, pause byte,
speed byte, pan byte, end byte]
//start byte = 255
//start run 0 and 1
//pause run 0 and 1
//speed = byte between 0 and 253
//pan = byte between 0 and 253
//end byte = 254
if (Serial.available()) { // If data available in serial
byte_from_app = Serial.read(); //read the next character available
if (byte_from_app == 255) { // look for start byte, if found:
bytesRecvd = 0; //reset byte received to 0(to start populating inputBuffer from start)
data_received = false;
}
else if (byte_from_app == 254) { // look for end byte, if found:
data_received = true; // set data_received to true so the data can be used
}
else { // add received bytes to buffer
inputBuffer[bytesRecvd] = byte_from_app; //add character to input buffer
bytesRecvd++; // increment byte received (this act as an index)
if (bytesRecvd == buffSize) { // just a security in case the inputBuffer fills up (shouldn't happen)
bytesRecvd = buffSize - 1; // if bytesReceived > buffer size set bytesReceived smaller than buffer size
}
}
}
}
I always try to fully understand any code I use from others, and do understand the above.
But I would like to do this without the mapping.
So my array from android would need to be something like;
1byteStart, 1byteRun, 1bytePause, 2byteSpeed, 2bytePan, 1byteEnd.
4hrs 23minutes later I am more confused now than at the start about how to process the order suggested above. Hence a call for help!
Would some kind soul put me out of my misery and throw me a snippet?