Hi,
I am facing one problem and don’t even know how to solve it. The code included is arduino bluetooth transmitter used in my esk8 build. It receives some values from the main bldc controller and transmits them straight to the receiver, where the values are displayed. Data transfer via bluetooth works properly. However, recently I decided to implement another feature for my eskate - wirelessly powered lights. On one side is 2.4Ghz transmitter and one of its channels is switch. On the other side is receiver. I hooked up pwm input to arduino and checking weather push button is pressed. So the problem is: my flashlight occasionally blinks (I guess when more data over bluetooth is flowing). Maybe there is a way to get rid of this problem? Thanks
Exactely what is connected to pin 5? In "setup()" you have an analogWrite on pin 9. In "loop()" you have digitalWrite's on the same pin. If your arduino (for some reason) resets, pin 9 will be turned half on in setup(), and then be shut off again in loop(). This may be the cause of the blinks.
Sorry, i missed that line. It was used for testing purposes only and it helped me to realize that flashlight is not blinking when turned on in the setup.
I didn’t see any reference to PWM in the brochure, but perhaps you’re thinking about PPM used to control RC servos?
You’ll have to identify more about the transmitter if you want to control it with an Arduino - or get rid of it altgether and drive the servos directly from Arduino ‘servo’ pins....
laikiux:
Actually, all of the rc controllers work in the same way...
OK. I did not know you were using a receiver that is intended to control a servo. Unfortunately the control signal for a servo is often called PWM even though it is completely different from the PWM that and Arduino produces.
Please explain again the overall purpose of the program and the problem you are having. I can't make enough sense of your Original Post.
What is an esk8?
What does this mean "It receives some values from the main bldc controller and transmits them straight to the receiver"? What is "it"? What is "the main bldc controller"? What is the "receiver"?
A simple diagram showing all the parts and how they relate to each other would be a good idea. See this Simple Image Guide
my goal is to get rig of a occasional blinking of my flashlights. Because of the intensive data sending over bluetooth, sometimes this part of code delays.
I do not know anything about the transmitter / receiver you are using, so it is hard to give good advice on that. But your sketch is constantly transmitting data over bluetooth, and if you think that is an issue, then try to limit the BT activity by modifying your sketch to something like:
Thank you for reply! Yes, the problem is that the data is constantly flowing over bluetooth and variable sec is not constantly checked. When it is interrupted this code line kiks in and turns flashlights off:
because it makes no allowance for the possibility that it starts measuring the time in the middle of a pulse. If it does that it would report a short pulse and (presumably) turn the light off briefly.
It may be made more reliable by checking the length of the short pulse to make sure it really is a short pulse - for example
sec = pulseIn(5, HIGH);
if (sec > 1500){
digitalWrite(9, HIGH);
}
else if (sec < 1200) { // this is probably the wrong number
digitalWrite(9, LOW);
}
If that is not sufficient then you may need to check for a few consecutive short pulses before turning off the light
…R
PS … if this was my project I would use a pair of nRF24L01+ transceivers for the wireless link. Simple nRF24L01+ Tutorial - much simpler than trying to measure a pulse width.
I would try to create a minimal sketch which only looks for pulses which turns on / off the flashlights. This makes it easier to figure out exactely which interval / pulse length to to use.