I’m currently developing a web application to control an electric longboard. I was able to obtain all my functionality in my initial set up with Arduino, but when I migrated from Arduino to photon my code no longer worked.
Description of my setup:
I have the 2.4Ghz Rc remote receiver plugged into my photon shield shield I need the 5v output. I confirmed that my photon was receiving the correctly by turning on/off the on board light. I knew the range of values (1400-2100) that my remote was inputting into the photon, by varying throttle. I confirmed this using the Serial monitor on Arduino. The receiver would normally be plugged directly into an ESC. But in order to limit the speed, I’m having pass through the photon so that I can limit the maximum value which occurs when the throttle is fully depressed.
This is my Arduino Code that functions like a charm!
#include <Servo.h>
Servo motor;
int rcPin = 10;
int val;
int limiter = 1600;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
motor.attach(3);
delay(1);
}
void loop() {
// put your main code here, to run repeatedly:
val = pulseIn(rcPin, HIGH);
if(val > limiter) {
motor.write(limiter);
}
else {
motor.write(val);
}
}
I transferred the code to my photon (removing the library and assigning the pins correctly) and I get no response from my esc. I’ve been reading online and it seems that this may be caused by the differences between the PWM of photon and Arduino but I’m just speculating I have no idea! Please help thank you!
@Ric Thanks for the reply, I’ve been assigning my pins like you mentioned. The above code is what i used in the arduino IDE and it work superb. I’ve been using the shield shield documentation to cross reference.
I’ve disconnected my rc remote because it works. I’m trying to pin point the issue by reducing the code. Still no response from my esc. Same code adapted for arduino works flawlessly.
Since there seem to be differences between the Arduino and the Photon, I think you need to give more information about your setup. Which Arduino board do you have that is working correctly? How exactly is the esc hooked up to the Arduino and Photon? The only thing that I can think of that would be different is the PWM frequency of the different hardware.
It’s not clear to me looking online what the frequency of PWM is for the Uno on pin 10. Do you have a way to measure that? The other main difference between the two boards, is that the Uno is operating at 5 volts and the Photon at 3.3.
What are you using the 5 volts on the shield for? If the ESC’s signal wire is hooked directly to a Photon pin, then that is only 3.3 volts. Do you know if that’s ok for your particular device? If not, you might want to put a transistor (maybe an n-channel MOSFET) in between the pin and the ESC, and have the transistor switch 5 volts controlled by the PWM signal from the Photon.
Can someone explain the above command. It does not seem to be in the docs. I assume you are setting the limits.
I have an ESC servo (from a quad copter) which I can only get going at one speed and stutters for other signals. Have tried several ideas. Not really sure if their is an easy method to try different frequencies. I think the default is 50 Hz but ESC use 500 HZ. Any suggestions here?