Hey guys.
I'm trying to adapt a code I've written for the Uno and XBee and import it to the Moteino.
In case you don't know what it is, here's a link http://lowpowerlab.com/moteino/:.
The sending unit has an optical encoder that sends either "up" or "down" signals.
The receiving unit translates this into "encoder ++" or "encoder --" and than uses the AccelStepper lib to move the stepper in the right direction.
Now something is wrong there, and I can't for the life if me figure it out.
What happens is that the encoder values do change, but the motor seems to vibrate but not rotate.
I have checked the motor, the Easydriver, and the optical encoder.
I even began by simply doing a fresh start and writing a new code to test a Moteino unit with encoder and stepper attached to it.
It worked just fine.
I'd really appreciate if someone could have a look at this code and tell me what's wrong.
Thank you.
////////////////////////
//Moteino FF Receiver///
////////////////////////#include <RFM12B.h>
#include <AccelStepper.h>
#include <avr/sleep.h>//int for radio data
int a;
int sum;//encoder/motor/driver setup
int easyDriverMicroSteps = 4;
int rotaryEncoderSteps = 75;
int motorStepsPerRev = 200;int MinPulseWidth = 50; //too low and the motor will stall, too high and it will slow it down
int easyDriverStepPin = 8;
int easyDriverDirPin = 9;
int enablePin = 10;volatile long encoderValue = 0;
byte dataReceive = 0;
long lastencoderValue = 0;//ON LED
#define onLed 12AccelStepper stepper(1, easyDriverStepPin, easyDriverDirPin);
//Sleep Function - to diable ED when not active
long previousMillis = 0;
int sleepTimer = 5000;// You will need to initialize the radio by telling it what ID it has and what network it's on
// The NodeID takes values from 1-127, 0 is reserved for sending broadcast messages (send to all nodes)
// The Network ID takes values from 0-255
// By default the SPI-SS line used is D10 on Atmega328. You can change it by calling .SetCS(pin) where pin can be {8,9,10}
#define NODEID 1 //network ID used for this unit
#define NETWORKID 99 //the network ID we are on
#define GATEWAYID 2 //the node ID we're sending to
#define SERIAL_BAUD 115200//encryption is OPTIONAL
//to enable encryption you will need to:
// - provide a 16-byte encryption KEY (same on all nodes that talk encrypted)
// - to call .Encrypt(KEY) to start encrypting
// - to stop encrypting call .Encrypt(NULL)
uint8_t KEY[] = "ABCDABCDABCDABCD";// Need an instance of the Radio Module
RFM12B radio;
byte sendSize=0;
char payload[] = "1234567890";
bool requestACK=false;void setup()
{
radio.Initialize(NODEID, RF12_433MHZ, NETWORKID);
radio.Encrypt(KEY); //comment this out to disable encryption
Serial.begin(SERIAL_BAUD);
Serial.println("Listening...");stepper.setMinPulseWidth(MinPulseWidth);
stepper.setMaxSpeed(50000); //variable to later determine speed play/rewind
stepper.setAcceleration(1000000000);
stepper.setSpeed(50000);pinMode(enablePin, OUTPUT);
}void loop()
{if(encoderValue != lastencoderValue)
{
digitalWrite (enablePin, LOW);
stepper.run();
int stepsPerRotaryStep = (motorStepsPerRev * easyDriverMicroSteps) / rotaryEncoderSteps;
stepper.moveTo(encoderValue * stepsPerRotaryStep);
lastencoderValue = encoderValue;
previousMillis = millis();
}
else
{
//Stepper sleep after 5sec of no data
unsigned long currentMillis = millis ();
if (currentMillis - previousMillis>sleepTimer)
digitalWrite (enablePin, HIGH);
}if (radio.ReceiveComplete())
{
if (radio.CRCPass())
{
sum = 0;
for (byte i = 0; i < radio.GetDataLen(); i++) //can also use radio.GetDataLen() if you don't like pointers
{
a = (radio.Data*);*
- sum+=a;*
- }*
_ Serial.println(sum);_- if (sum == 49)*
- {*
- encoderValue++;*
_ Serial.println(encoderValue);_- }*
- else if (sum == 99)*
- {*
- encoderValue--;*
_ Serial.println(encoderValue);_- }*
- }*
- }*
}
[/quote]