Im using a potemtiometer to control a servo wirelessly, everything works fine %70 off the time, sometimes i need to push the reset button a few times before it starts working and if i leave it on for about 10+ minutes i need to restart it to get it working, on the times when a reset is neeeded to get it working, the tx sends 1 message only when its supposed tio continuosly do it thru a loop, here is the code.
tx:
#include <SPI.h> //the communication interface with the modem
#include "RF24.h" //the library which helps us to control the radio modem
const int potPin = A0; //Ssying that the potentiometer is at pin A0
RF24 radio(9, 10); //5 and 10 are a digital pin numbers to which signals CE and CSN are connected.
const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem, that will receive data from Arduino.
int value; //Variable to store data to send
void setup(void)
{
Serial.begin(9600);
radio.begin(); //it activates the modem.
radio.openWritingPipe(pipe); //sets the address of the receiver to which the program will send data.
}
void loop(void)
{
static unsigned long timer = 0; //Timer to tell
unsigned long interval = 10; //The program when to
if (millis() - timer >= interval) //Send new data since it is a loop
{
timer = millis();
value = analogRead(potPin); //Variable is equal to voltage on potentiometer
value = map(analogRead(A0), 0, 1023, 0, 180); //Converting the voltage read to values we need
Serial.print("sent data ");
Serial.println(value);
radio.write(&value, sizeof(value)); //Basically means --> radio.SendMsg(Send this value,use this much memory to send it)
}
}
rx:
#include <Servo.h> //Servo librart
#include <SPI.h> //the communication interface with the modem
#include "RF24.h" //the library which helps us to control the radio modem
Servo myServo; //define the servo name
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem,that will receive data from the Arduino.
int msg; //Created integer value variable to store received data
void setup(){
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(5,OUTPUT);
Serial.begin(9600);
myServo.attach(3); //3 is a digital pin to which servo signal connected.
radio.begin(); //it activates the modem.
radio.openReadingPipe(1, pipe); //determines the address of our modem which receive data.
radio.startListening(); //enable receiving data via modem
}
void loop(){
if(radio.available()){ //checks whether any data have arrived at the address of the modem
radio.read(&msg,sizeof(msg)); //Basically means ---> radio.CheckForMsg(Store it at this location,reserve this much storage for it)
Serial.print("incoming ");
Serial.println(msg);
myServo.write(msg); //Tells servo to move to degrees of msg variable
}
}
You seem to be sending data 100 times per second. Try reducing that to 10 times per second - it should be plenty fast enough.
Another thought is to increase the baud rate from 9600 to (say) 115200 so that the serial output buffer empties more quickly. An Arduino will stall while the buffer is too full to take more data.
Of course reducing the frequency of sending messages will also reduce the load on Serial.
Ok ive change teh baud rate to 115200 and hwo do i chage it from 100 times/s to 10 times/s , and another this is that when i changed the baud rate my output is some random characters all in one row
Railroader:
Not being playing with wireless yet, so..... Is it the Tx device that jams up and needs resetting and hte Rx is running without resets?
The tx is the one that needs to be constantly reset
Make sure that both sender and receiver uses the same baudrate. You can't change only in one place.
How to change fromm 100 Hz to 10? What made You write thsi code: unsigned long interval = 10; //The program when to
Do some calculation of transmission time needed for both Serial and the radio link. That could give an idea about the maximum times per second loop() can run. Try some other intervals like 50. If this works try 25 else try 75.
Ok. Cut down the transmission rate to 1 per second, just to find out what's wrong.
I see that the rx-loop() runs at top speed. Is it possible that a too high data rate would send servo data at a too high rate? As I think, bringing down that data flow calls for bringing down the data rate sent by tx-loop.
Maybe You can, in Rx, Serial.print millis() and see the incoming data rate?
no, i didnt rewire anything but the problem seemed to be the shield board i atatched to the arduino, whenever i would connect , the sketch would say the port isnt recogized, but i took it off and the burning smell is gone, but the problem is still there
it as a prototyping shield board, thinking about it i think that was when its stopped working more often, it was still pausing every now and then before, but now its literally not moving and sending once evry time i reset it
Don't add any new physical stuff to a troubeling project. Try to get back to the most working/lest failing rigging and make that work. Then we can discuss how to proceed.
its not working now, it only sends one message to the rx but that only works when i unplug and plug the rx , so it in a worse position than when i started any ideas?
.
Shit. When You write "unplug and plug Rx", do You mean disconnecting/connecting Vcc of the Rx unit?
Don't make any disconnecting/connecting wires on units being powered. That's called "hot swap" and will(!) kill most hardware.
Does the Tx unit run properly? Where was that proto-board attached? To the Rx unit?
i meant removing the usb cable that powered the arduino and allow me to uplaod sketches to it and what do you mean by"Don't make any disconnecting/connecting wires on units being powered", the tx doesnt work properly msot of the time and the proto board was attached to the rx unit