Hello all,
So I'm mostly through a project getting animatronic eyes to work with an R/C controller..
The 2 arduinos communicate (can send text back and forth on serial monitor), and with the original 1 board assembly, the servos and joystick play well with each other. However, when I try and send the data I do get a response.. but it's just basically noise movement in the servo vs taking input from the joystick.
Using an Uno for the transmitter, and a Nano with PCA9685 16 Channel 12-bit PWM Servo motor Driver, and both are using NRF24L01 to communicate
// Nilheim Mechatronics Simplified Eye Mechanism Code
// Make sure you have the Adafruit servo driver library installed >>>>> https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library
// X-axis joystick pin: A1
// Y-axis joystick pin: A0
// Trim potentiometer pin: A2
// Button pin: 2
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 140 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX 520 // this is the 'maximum' pulse length count (out of 4096)
// our servo # counter
uint8_t servonum = 0;
int xval;
int yval;
int lexpulse;
//int rexpulse;
int leypulse;
int leypulseM;
//int reypulse;
//int trimval;
//const int analogInPin = A0;
//int sensorValue = 0;
//int outputValue = 0;
//int switchval = 0;
void setup() {
Serial.begin(9600);
Serial.println("8 channel Servo test!");
pinMode(analogInPin, INPUT);
pinMode(2, INPUT);
pwm.begin();
pwm.setPWMFreq(50); // Analog servos run at ~60 Hz updates
delay(10);
}
// you can use this function if you'd like to set the pulse length in seconds
// e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. its not precise!
void setServoPulse(uint8_t n, double pulse) {
double pulselength;
pulselength = 1000000; // 1,000,000 us per second
pulselength /= 50; // 60 Hz
Serial.print(pulselength); Serial.println(" us per period");
pulselength /= 4096; // 12 bits of resolution
Serial.print(pulselength); Serial.println(" us per bit");
pulse *= 1000000; // convert to us
pulse /= pulselength;
Serial.println(pulse);
}
void loop() {
xval = analogRead(A0);
lexpulse = map(xval, 0,1023, 220, 300);
//rexpulse = lexpulse;
switchval = digitalRead(2);
yval = analogRead(A1);
leypulse = map(yval, 0,1023, 350, 450);
leypulseM = map(yval, 0,1023, 450, 350);
// reypulse = map(yval, 0,1023, 400, 280);
// trimval = analogRead(A2);
// trimval=map(trimval, 320, 580, -40, 40);
pwm.setPWM(0, 0, lexpulse);
pwm.setPWM(1, 0, lexpulse);
pwm.setPWM(2, 0, leypulse);
pwm.setPWM(3, 0, leypulseM);
Serial.println(trimval);
delay(5);
}
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 140 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX 520 // this is the 'maximum' pulse length count (out of 4096)
// our servo # counter
uint8_t servonum = 0;
int xval;
int yval;
int lexpulse;
//int rexpulse;
int leypulse;
int leypulseM;
//int reypulse;
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "SNIT1";
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
Serial.begin(9600);
Serial.println("8 channel Servo test!");
// pinMode(analogInPin, INPUT);
pinMode(2, INPUT);
pwm.begin();
pwm.setPWMFreq(50); // Analog servos run at ~60 Hz updates
delay(10);
}
void loop () {
delay(5);
radio.stopListening();
xval = analogRead(A0);
lexpulse = map(xval, 0,1023, 220, 300);
//rexpulse = lexpulse;
// switchval = digitalRead(2);
yval = analogRead(A1);
leypulse = map(yval, 0,1023, 350, 450);
leypulseM = map(yval, 0,1023, 450, 350);
radio.write(&leypulse, sizeof(leypulse));
radio.write(&leypulseM, sizeof(leypulseM));
radio.write(&lexpulse, sizeof(lexpulse));
}
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 140 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX 520 // this is the 'maximum' pulse length count (out of 4096)
// our servo # counter
uint8_t servonum = 0;
int xval;
int yval;
int lexpulse;
//int rexpulse;
int leypulse;
int leypulseM;
//int reypulse;
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "SNIT1";
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
Serial.begin(9600);
Serial.println("8 channel Servo test!");
//pinMode(analogInPin, INPUT);
//pinMode(2, INPUT);
pwm.begin();
pwm.setPWMFreq(50); // Analog servos run at ~60 Hz updates
delay(10);
}
void loop () {
delay(5);
radio.startListening();
if (radio.available()) {
while(radio.available()){
int lexpulse=0;
int leypulse=0;
int leypulseM=0;
radio.read(&lexpulse, sizeof(lexpulse));
radio.read(&leypulseM, sizeof(leypulseM));
radio.read(&leypulse, sizeof(leypulse));
pwm.setPWM(0, 0, lexpulse);
pwm.setPWM(1, 0, lexpulse);
pwm.setPWM(2, 0, leypulse);
pwm.setPWM(3, 0, leypulseM);
}
}
}
Thanks so much for the help community... I feel like I'm close but not quite there yet!!!