HobbyKing.com New Products Flash Sale
Reply
Thread Tools
Old Mar 01, 2013, 08:07 AM
Registered User
Joined Dec 2012
95 Posts
Good stuff. As a suggestion, you can solve the problem of not having high-quality pots by switching to a rotary encoder with detents. Not as a cheap as a pot, but also not very expensive, either. A rotary encoder counts how many steps and in which direction that the dial is turned, and they are free spinning. It requires a few pins to do, but the code is easy -- you can just grab the code from the sample sketch that comes with the Arduino IDE. It is interrupt-based. Meaning, when you turn the rotary encoder, it triggers an interrupt that is used to update whatever value you are controlling. Then in your regular loop, you can just read this global value whenever you need to. Anyway, the nice thing about this is you can smoothly go from 00 to 99 with 100% accuracy all the time. I'm using a rotary encoder for my rudder tiller.

One other thing... You can adjust the code so that it takes several steps before your value is updated. You could make it so it takes 10 steps before your 00-99 value changes. This would eliminate your channel from changing from accidental bumps.
Skystream is offline Find More Posts by Skystream
Last edited by Skystream; Mar 01, 2013 at 08:14 AM.
Reply With Quote
Sign up now
to remove ads between posts
Old Mar 01, 2013, 05:55 PM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
270 Posts
There is one little problem with rotery-pots. I have one in the transmitter for the menu. Because it uses HIGH/LOW input, I can't read/remember the last channel used/selected. The NRF units get there channel at the startup of the arduino. Thats why I read an analog value. That's'why I also need to push the reset button each time I change the channel.

But, I have only a small bit of knowledge about C++ programming (learning by doing). If you have a better option, please try it and post the solution. It is Open Source.

Danny
Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Old Mar 02, 2013, 10:28 AM
Registered User
Joined Dec 2012
95 Posts
Simple to address. You just need to store your value in the Arduino's built in EEPROM whenever the value changes, and read the value out of EEPROM when you start up. See the EEPROM sample sketches. The arduino UNO had 512 bytes of EEPROM and the mega has 1024.
Skystream is offline Find More Posts by Skystream
Reply With Quote
Old Mar 02, 2013, 04:39 PM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
270 Posts
OK Skystream, I'll look in to it. Like I said, learning by doing. Don't hold your breath, it might take a while because I also have to finish the transmitter. I have no experience with EEPROMs, it sounds like they are the solution. I never had any use for them yet.

Danny
Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Old Mar 03, 2013, 06:04 AM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
270 Posts
With rotary encoder

To Skystream and others,
You we're right, the EEPROM is easier then I thought. I've connected a rotary encoder to pin A8 and A9. A temporary reset connected to A10. The encoder has 3 pin on a side. The middle pin is connented to GND. The other two have a 10K resistor to 5V and are connected to A8 and A9. The other side has two pins. One goes to A10 and has a 10k pulldown resistor to gnd. The other pin goes to 5V. Don't rotate the encoder to fast, it needs time to read. The value the arduino needs to remember goes to EEPROM address 0. The code still needs some cleaning up. You now have two ways to select a channel. 1: 10K pot and a seperate reset button, or 2: the rotary encoder. The rotary version can set a channel from 01 to 99

Time to build the demo transmitter version and also implement the rotary encoder next to the pot selection. My old transmitter needs reworking .

grtz.

Danny

EDIT: code REALLY needs cleaning up.

Code:
#include <Servo.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <Wire.h>
#include <EEPROM.h>

#define expander1 B0111000
#define expander2 B0100000

const int chlow = 80; // set lowest channel number with pot channel selection
const int chhi = 99; // set highest channel number with pot channel selection

//#define DEBUG // uncomment for feedback through the serialmonitor
//#define DynChannel // comment for setting dynamic channel select. 
                     // Ananolg pin 13 for potmeter. Reset to use channel
//#define RESET // do you have want resetbutton? 
                // Stick it on pin A15, and add a 10K pulldown. Led on pin A14
#define DynChannelrotary // channel select and push for selecting the channel

int channel = 80; // what channel are we on? // comment for dynamic channel control
int channelold;
char buffer[64]; 
char msg[140] = "";
int b;

// let's define some servo's
Servo servo1; Servo servo2; Servo servo3; Servo servo4; 
Servo servo5; Servo servo6; /*Servo servo7; Servo servo8; */
Servo servo9; Servo servo10; Servo servo11; Servo servo12;
// minimum and maximum range for the servo
int servmin1 = 16; int servmax1 = 177; 
int servmin2 = 16; int servmax2 = 177;
int servmin3 = 16; int servmax3 = 177; 
int servmin4 = 16; int servmax4 = 177;
int servmin5 = 16; int servmax5 = 177; 
int servmin6 = 16; int servmax6 = 177;
/*int servmin7 = 0; int servmax7 = 255; 
int servmin8 = 0; int servmax8 = 255;*/
int servmin9 = 16; int servmax9 = 177; 
int servmin10 = 16; int servmax10 = 177;
int servmin11 = 16; int servmax11 = 177;
int servmin12 = 16; int servmax12 = 177;

int pinNumber; int pinValue;
int Pin22 = 22; int Pin23 = 23; int Pin24 = 24; int Pin25 = 25;
int Pin26 = 26; int Pin27 = 27; int Pin28 = 28; int Pin29 = 29;
int Pin30 = 30; int Pin31 = 31; int Pin32 = 32; int Pin33 = 33;
int Pin34 = 34; int Pin35 = 35; int Pin36 = 36; int Pin37 = 37;
int Pin38 = 38; int Pin39 = 39; int Pin40 = 40; int Pin41 = 41;
int Pin42 = 42; int Pin43 = 43; int Pin44 = 44; int Pin45 = 45;
int Pin46 = 46; int Pin47 = 47; int Pin48 = 48; int Pin49 = 49;
int Pin53 = 53; int Pin8 = A0; int Pin9 = A1; int Pin10 = A2;
int Pin11 = A3; int Pin12 = A4; int Pin13 = A5; 
int Pin14 = A6; int Pin15 = A7; 

#ifdef RESET
const int resetPin = A15;          // the number of the pushbutton pin
const int ResetState = 0;        // variable for reading the pushbutton status
const int resetled = A14;         // light up led when reset
const int timetoreset = 500;     // how long delay after reset
#endif

#ifdef DynChannel // read with 
const int ChannelPin = A13;      // select the input pin for the channel select
int ChannelValue = 0;            // temp. channel until read
//int channelold;                  // just needed as a default when setting channel dynamic
#endif

#ifdef DynChannelrotary
int address = 1;
const int ResetState = 0;        // variable for reading the pushbutton status
const int timetoreset = 1000;     // how long delay after reset
int ChannelValue = 0;            // temp. channel until read
const int Pin_Highbit =A8;    // first pin of rotary
const int Pin_Lowbit =A9;     // third pin of rotary
const int buttonPin = A10;     // the number of the pushbutton pin (temp A10 -> A15
int rotarychannel = 1;
int value;

int state, prevState = 0, count = 0; 
int pushed = 0; int buttonState = 0; 
int encoderStates[4][4] = {
  {  0, -1,  1,  0   }, 
  {  1,  0,  0, -1   }, 
  { -1,  0,  0,  1   }, 
  {  0,  1, -1,  0   }, 
};
#endif

// nRF24L01(+) radio attached to SPI and pins 8 & 9
RF24 radio(8,9);

// Network uses that radio
RF24Network network(radio);

// Address of our node
const uint16_t this_node = 0; // the receiver code

// Address of the other node
const uint16_t other_node = 1; // the transmittercode

void defaultvalues(){ 
}

void setup(void)
{
  #ifdef RaspberryPiComm
    Serial.begin(115200);
  #endif

#ifdef DynChannelrotary
  pinMode(Pin_Highbit, INPUT);
  pinMode(Pin_Lowbit, INPUT);
  digitalWrite(Pin_Lowbit, HIGH);
  digitalWrite(Pin_Highbit, HIGH);
  pinMode(buttonPin, INPUT); 
#endif

  Wire.begin();

  pinMode(Pin22, OUTPUT); pinMode(Pin23, OUTPUT);
  pinMode(Pin24, OUTPUT); pinMode(Pin25, OUTPUT);
  pinMode(Pin26, OUTPUT); pinMode(Pin27, OUTPUT);
  pinMode(Pin28, OUTPUT); pinMode(Pin29, OUTPUT);
  pinMode(Pin30, OUTPUT); pinMode(Pin31, OUTPUT);
  pinMode(Pin32, OUTPUT); pinMode(Pin33, OUTPUT);
  pinMode(Pin34, OUTPUT); pinMode(Pin35, OUTPUT);
  pinMode(Pin36, OUTPUT); pinMode(Pin37, OUTPUT);
  pinMode(Pin38, OUTPUT); pinMode(Pin39, OUTPUT);
  pinMode(Pin40, OUTPUT); pinMode(Pin41, OUTPUT);
  pinMode(Pin42, OUTPUT); pinMode(Pin43, OUTPUT);
  pinMode(Pin44, OUTPUT); pinMode(Pin45, OUTPUT);
  pinMode(Pin46, OUTPUT); pinMode(Pin47, OUTPUT);
  pinMode(Pin48, OUTPUT); pinMode(Pin49, OUTPUT);
  pinMode(Pin53, OUTPUT); 
  pinMode(Pin8, OUTPUT); pinMode(Pin9, OUTPUT);
  pinMode(Pin10, OUTPUT); pinMode(Pin11, OUTPUT);
  pinMode(Pin12, OUTPUT); pinMode(Pin13, OUTPUT);
  pinMode(Pin14, OUTPUT); pinMode(Pin15, OUTPUT);
  
  digitalWrite(Pin22, LOW); digitalWrite(Pin23, LOW);
  digitalWrite(Pin24, LOW); digitalWrite(Pin25, LOW);
  digitalWrite(Pin26, LOW); digitalWrite(Pin27, LOW);
  digitalWrite(Pin28, LOW); digitalWrite(Pin29, LOW);
  digitalWrite(Pin30, LOW); digitalWrite(Pin31, LOW);
  digitalWrite(Pin32, LOW); digitalWrite(Pin33, LOW);
  digitalWrite(Pin34, LOW); digitalWrite(Pin35, LOW);
  digitalWrite(Pin36, LOW); digitalWrite(Pin37, LOW);
  digitalWrite(Pin38, LOW); digitalWrite(Pin39, LOW);
  digitalWrite(Pin40, LOW); digitalWrite(Pin41, LOW);
  digitalWrite(Pin42, LOW); digitalWrite(Pin43, LOW);
  digitalWrite(Pin44, LOW); digitalWrite(Pin45, LOW);
  digitalWrite(Pin46, LOW); digitalWrite(Pin47, LOW);
  digitalWrite(Pin48, LOW); digitalWrite(Pin49, LOW);
  digitalWrite(Pin53, LOW); 
  digitalWrite(Pin8, LOW); digitalWrite(Pin9, LOW);
  digitalWrite(Pin10, LOW); digitalWrite(Pin11, LOW);
  digitalWrite(Pin12, LOW); digitalWrite(Pin13, LOW);
  digitalWrite(Pin14, LOW); digitalWrite(Pin15, LOW);
  
#ifdef RESET  
  pinMode(resetPin, INPUT);
  pinMode(resetled, OUTPUT); 
#endif  
  Serial.begin(9600);
#ifdef DEBUG
  Serial.println("RF24Network/nummeriek protocol ontvangerzijde");
  Serial.print("Encoder channel: ");
  Serial.println(channel);
#endif

// sound serial 1
 // Serial1.begin(9600);

//  what servo goes in what port
  servo1.attach(2); servo2.attach(3); servo3.attach(4); servo4.attach(5); 
  servo5.attach(6); servo6.attach(7); /*servo7.attach(10); servo8.attach(11); */
  servo9.attach(10); servo10.attach(11); servo11.attach(12); servo12.attach(13);   

#ifdef DynChannel
  ChannelValue = analogRead (ChannelPin);
  int channel = map(ChannelValue,0,1023,chlow,chhi); 
b = channel;
if (b==0){expanderWrite1(B10111110);}
if (b>=90){expanderWrite1(B11110110);b=b-90;}
if (b>=80){expanderWrite1(B11111110);b=b-80;}
if (b>=70){expanderWrite1(B00110010);b=b-70;}
if (b>=60){expanderWrite1(B11101110);b=b-60;}
if (b>=50){expanderWrite1(B11100110);b=b-50;}
if (b>=40){expanderWrite1(B11010010);b=b-40;}
if (b>=30){expanderWrite1(B01110110);b=b-30;}
if (b>=20){expanderWrite1(B10111100);b=b-20;}
if (b>=10){expanderWrite1(B00010010);b=b-10;}

//expanderWrite2(B00001000); // dot
if (b==0){expanderWrite2(B10111110);}
if (b==1){expanderWrite2(B00010010);}
if (b==2){expanderWrite2(B01111100);}
if (b==3){expanderWrite2(B01110110);}
if (b==4){expanderWrite2(B11010010);}
if (b==5){expanderWrite2(B11100110);}
if (b==6){expanderWrite2(B11101110);}
if (b==7){expanderWrite2(B00110010);}
if (b==8){expanderWrite2(B11111110);}
if (b==9){expanderWrite2(B11110110);}
//Serial.println(channel);
delay(10);

#endif

#ifdef DynChannelrotary
value = EEPROM.read(0);
delay(100);
count = value*4;
//count = count*4;
channel = count/4;
//channel = channel / 4;
//Serial.println(value,DEC);
//delay(1000);
b = channel;
if (b==0){expanderWrite1(B10111110);}
if (b>=90){expanderWrite1(B11110110);b=b-90;}
if (b>=80){expanderWrite1(B11111110);b=b-80;}
if (b>=70){expanderWrite1(B00110010);b=b-70;}
if (b>=60){expanderWrite1(B11101110);b=b-60;}
if (b>=50){expanderWrite1(B11100110);b=b-50;}
if (b>=40){expanderWrite1(B11010010);b=b-40;}
if (b>=30){expanderWrite1(B01110110);b=b-30;}
if (b>=20){expanderWrite1(B10111100);b=b-20;}
if (b>=10){expanderWrite1(B00010010);b=b-10;}

//expanderWrite2(B00001000); // dot
if (b==0){expanderWrite2(B10111110);}
if (b==1){expanderWrite2(B00010010);}
if (b==2){expanderWrite2(B01111100);}
if (b==3){expanderWrite2(B01110110);}
if (b==4){expanderWrite2(B11010010);}
if (b==5){expanderWrite2(B11100110);}
if (b==6){expanderWrite2(B11101110);}
if (b==7){expanderWrite2(B00110010);}
if (b==8){expanderWrite2(B11111110);}
if (b==9){expanderWrite2(B11110110);}
//Serial.println(channel);
delay(10);
#endif

  SPI.begin();
  radio.begin();
  network.begin(/*channel*/ channel, /*node address*/ this_node);
#ifdef commpin53
  digitalWrite(commpin,HIGH);         
#endif
}
#ifdef RESET
void(* resetFunc) (void) = 0; //declare reset function @ address 0
#endif

#ifdef DynChannelrotary
void(* resetFunc) (void) = 0; //declare reset function @ address 0
#endif

void loop(void) 
{   
  
#ifdef DynChannelrotary
  state = (digitalRead(Pin_Highbit) << 1) | digitalRead(Pin_Lowbit);
  count += encoderStates[prevState][state];
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  // check if the pushbutton is pressed and debounce
  if (buttonState == HIGH && pushed==0) {// reset pushed
    // Reset: 
    Serial.print("eeprom value: "); Serial.println(value);
    EEPROM.write(0, value);
    delay(timetoreset);
    resetFunc();  //call reset
    pushed =1;
  } 
  if (buttonState == LOW && pushed==1) {// reset released    
    // do nothing
    pushed=0; 
  }
  prevState = state; 

  if (state != prevState) {}// perhaps in the future
    if (count <=0){count=0;} // nothing less then 0
    channel = count/4;
    if (count >=396){count=396;} // nothing more then 396
  b = channel;
  if (channel != channelold){
//if (b==0){expanderWrite1(B01110111);}
if (b<10){expanderWrite1(B01111110);}
if (b>=90){expanderWrite1(B11110110);b=b-90;}
if (b>=80){expanderWrite1(B11111110);b=b-80;}
if (b>=70){expanderWrite1(B00110010);b=b-70;}
if (b>=60){expanderWrite1(B11101110);b=b-60;}
if (b>=50){expanderWrite1(B11100110);b=b-50;}
if (b>=40){expanderWrite1(B11010010);b=b-40;}
if (b>=30){expanderWrite1(B10110110);b=b-30;}
if (b>=20){expanderWrite1(B10111100);b=b-20;}
if (b>=10){expanderWrite1(B00010010);b=b-10;}

//expanderWrite2(B00001000); // dot
if (b==0){expanderWrite2(B10111110);}
if (b==1){expanderWrite2(B00010010);}
if (b==2){expanderWrite2(B01111100);}
if (b==3){expanderWrite2(B01110110);}
if (b==4){expanderWrite2(B11010010);}
if (b==5){expanderWrite2(B11100110);}
if (b==6){expanderWrite2(B11101110);}
if (b==7){expanderWrite2(B00110010);}
if (b==8){expanderWrite2(B11111110);}
if (b==9){expanderWrite2(B11110110);}
delay(10);
 value = count/4;
 //Serial.print(value); Serial.print("  /  "); Serial.println(channel); 
  }
#endif

#ifdef RESET
  // reset button
  int ResetState = analogRead(resetPin);
  if (ResetState >= 10) {     
 //   analogWrite(resetled,100); // just ot test button
    delay(timetoreset);
    resetFunc();  //call reset
  }
  else {
 //   analogWrite(resetled,20);
  }  
#endif

#ifdef DynChannel
  ChannelValue = analogRead (ChannelPin);
  int channel = map(ChannelValue,0,1023,chlow,chhi);
  b = channel;
  if (channel != channelold){
    if (b==0){expanderWrite1(B01110111);}
if (b==0){expanderWrite1(B10111110);}
if (b>=90){expanderWrite1(B11110110);b=b-90;}
if (b>=80){expanderWrite1(B11111110);b=b-80;}
if (b>=70){expanderWrite1(B00110010);b=b-70;}
if (b>=60){expanderWrite1(B11101110);b=b-60;}
if (b>=50){expanderWrite1(B11100110);b=b-50;}
if (b>=40){expanderWrite1(B11010010);b=b-40;}
if (b>=30){expanderWrite1(B01110110);b=b-30;}
if (b>=20){expanderWrite1(B10111100);b=b-20;}
if (b>=10){expanderWrite1(B00010010);b=b-10;}

//expanderWrite2(B00001000); // dot
if (b==0){expanderWrite2(B10111110);}
if (b==1){expanderWrite2(B00010010);}
if (b==2){expanderWrite2(B01111100);}
if (b==3){expanderWrite2(B01110110);}
if (b==4){expanderWrite2(B11010010);}
if (b==5){expanderWrite2(B11100110);}
if (b==6){expanderWrite2(B11101110);}
if (b==7){expanderWrite2(B00110010);}
if (b==8){expanderWrite2(B11111110);}
if (b==9){expanderWrite2(B11110110);}
delay(10);
  }
#endif 

#ifdef DEBUG
  if (channelold != channel){
    Serial.print("Channel: ");
    Serial.print(channel);
    Serial.print("    ");
    channelold = channel;
  }
#endif 

  // Pump the network regularly
  network.update();

  // Is there anything ready for us?
  while ( network.available() )
  {
    // If so, grab it and print it out
    RF24NetworkHeader header;
    static char message[64];
    network.read(header,message,sizeof(message));
    splitString(message);
  }
}

void splitString(char* data) {  
  char* parameter; 
  parameter = strtok (data, " ,"); 
  while (parameter != NULL) { 
    setFunctionelegroep(parameter); 
    parameter = strtok (NULL, " ,"); 
  } 
  // Clear the text and serial buffers 
  for (int x=0; x<64; x++) { 
    buffer[x]='\0'; 
  } 
  //  Serial.flush(); 
}

// initialiseer functie. Gewoon i typen en alles gaat naar 0 en middenpositie
void setFunctionelegroep(char* data) { 

//------------------- Start functionele groep 1 ---------------------//
  if (data[0] == '1') { // funtionele groep 
    int servoin1 = strtol(data+1, NULL, 10); 

//-------------- Groep1 / Servo 1 input/checker/send ----------------//
    if (servoin1 >= 1000 && servoin1 <1500){
      int serv1 = servoin1 - 1000;
      if (serv1 >=0){
        serv1 = map(serv1, 0, 255, servmin1, servmax1);
#ifdef DEBUG
        Serial.print("Servo 1 is set to: ");
        Serial.println(serv1); 
#endif
#ifdef Servo01
Serial.println(servoin1);
#endif
        servo1.write(serv1); 
      }
    }
//-------------   End of groep 1 / Servo 1 control   ----------------//   

//-------------- Groep1 / Servo 2 input/checker/send ----------------//
    if (servoin1 >= 1500 && servoin1 <2000){
      int serv2 = servoin1 - 1500;
      if (serv2 >=0){
        serv2 = map(serv2, 0, 255, servmin2, servmax2);
#ifdef DEBUG
        Serial.print("Servo 2 is set to: ");
        Serial.println(serv2); 
#endif
#ifdef Servo02
Serial.println(servoin1);
#endif
        servo2.write(serv2); 
      }
    }
//-------------   End of groep 1 / Servo 2 control   ----------------// 

//-------------- Groep1 / Servo 3 input/checker/send ----------------//
    if (servoin1 >= 2000 && servoin1 <2500){
      int serv3 = servoin1 - 2000;
      if (serv3 >=0){
        serv3 = map(serv3, 0, 255, servmin3, servmax3);
#ifdef DEBUG
        Serial.print("Servo 3 is set to: ");
        Serial.println(serv3); 
#endif
#ifdef Servo03
Serial.println(servoin1);
#endif
        servo3.write(serv3); 
      }
    }
//-------------   End of groep 1 / Servo 3 control   ----------------// 

//-------------- Groep1 / Servo 4 input/checker/send ----------------//
    if (servoin1 >= 2500 && servoin1 <3000){
      int serv4 = servoin1 - 2500;
      if (serv4 >=0){
        serv4 = map(serv4, 0, 255, servmin4, servmax4);
#ifdef DEBUG
        Serial.print("Servo 4 is set to: ");
        Serial.println(serv4); 
#endif
#ifdef Servo04
Serial.println(servoin1);
#endif
    servo4.write(serv4); 
        
      }
    }
//-------------   End of groep 1 / Servo 2 control   ----------------// 

//-------------- Groep1 / Servo 5 input/checker/send ----------------//
    if (servoin1 >= 3500 && servoin1 <4000){
      int serv5 = servoin1 - 2500;
      if (serv5 >=0){
        serv5 = map(serv5, 0, 255, servmin5, servmax5);
#ifdef DEBUG
        Serial.print("Servo 5 is set to: ");
        Serial.println(serv5); 
#endif
#ifdef Servo05
Serial.println(servoin1);
#endif
    servo5.write(serv5); 
        
      }
    }
//-------------   End of groep 1 / Servo 5 control   ----------------//

//-------------- Groep1 / Servo 6 input/checker/send ----------------//
    if (servoin1 >= 4000 && servoin1 <4500){
      int serv6 = servoin1 - 2500;
      if (serv6 >=0){
        serv6 = map(serv6, 0, 255, servmin6, servmax6);
#ifdef DEBUG
        Serial.print("Servo 6 is set to: ");
        Serial.println(serv6); 
#endif
#ifdef Servo06
Serial.println(servoin1);
#endif
    servo6.write(serv6); 
        
      }
    }
//-------------   End of groep 1 / Servo 2 control   ----------------//

//-------------- Groep1 / Servo 9 input/checker/send ----------------//
    if (servoin1 >= 5000 && servoin1 <5500){
      int serv9 = servoin1 - 5000;
      if (serv9 >=0){
        serv9 = map(serv9, 0, 255, servmin9, servmax9);
#ifdef DEBUG
        Serial.print("Servo 9 is set to: ");
        Serial.println(serv9); 
#endif
#ifdef Servo07
Serial.println(servoin1);
#endif
        servo9.write(serv9); 
      }
    }
//-------------   End of groep 1 / Servo 9 control   ----------------// 

//-------------- Groep1 / Servo 10 input/checker/send ----------------//
    if (servoin1 >= 5500 && servoin1 <6000){
      int serv10 = servoin1 - 5500;
      if (serv10 >=0){
        serv10 = map(serv10, 0, 255, servmin10, servmax10);
#ifdef DEBUG
        Serial.print("Servo 10 is set to: ");
        Serial.println(serv10); 
#endif
#ifdef Servo08
Serial.println(servoin1);
#endif
        servo10.write(serv10); 
      }
    }
//-------------   End of groep 1 / Servo 10 control   ----------------// 

//-------------- Groep1 / Servo 11  Volume 1 ----------------//
    if (servoin1 >= 6000 && servoin1 <6500){
      int serv11 = servoin1 - 6000;
      if (serv11 >=0){
        serv11 = map(serv11, 0, 255, servmin11, servmax11);
#ifdef DEBUG
        Serial.print("Servo 11 is set to: ");
        Serial.println(serv11); 
#endif
#ifdef Servo09
Serial.println(servoin1);
#endif
        servo11.write(serv11); 
      }
    }
//-------------   End of groep 1 / Volume 1   ----------------// 

//-------------- Groep1 / Servo 12 Volume 2  ----------------//
    if (servoin1 >= 6500 && servoin1 <7000){
      int serv12 = servoin1 - 6500;
      if (serv12 >=0){
        serv12 = map(serv12, 0, 255, servmin12, servmax12);
#ifdef DEBUG
        Serial.print("Servo 12 is set to: ");
        Serial.println(serv12); 
#endif
#ifdef Servo10
Serial.println(servoin1);
#endif
        servo12.write(serv12); 
      }
    }
//-------------   End of groep 1 / Volume 2   ----------------// 

} // einde functionele groep 1


//------------------- Start functionele groep 2 ---------------------//
  if (data[0] == '2') { // funtionele groep 
    int buttonin1 = strtol(data+1, NULL, 10); 

//-------------- Groep2 / buttongroep 1 D22->D28 -----------//
  if ( buttonin1 >= 1000 && buttonin1 <1500){
    int butto1 = buttonin1 - 1000;
    if (butto1 >=0){
#ifdef DEBUG
  Serial.print("buttongroep1 code is: ");
  Serial.println(butto1); 
#endif
////////////////////////////////// D22 ///////////////////////////////
  if (butto1 >= 128) {
    digitalWrite(Pin22, HIGH);
#ifdef DEBUG
  Serial.println("Pin22 = on");
#endif
    butto1 = (butto1 - 128); 
  }
  else {
    digitalWrite(Pin22, LOW);
  }
////////////////////////////////// D23 ///////////////////////////////
  if (butto1 >= 64) {
    digitalWrite(Pin23, HIGH);
#ifdef DEBUG
  Serial.println("Pin23 = on"); 
#endif
    butto1 = (butto1 - 64);
  }  
  else {
    digitalWrite(Pin23, LOW);
  }
////////////////////////////////// D24 ///////////////////////////////
  if (butto1 >= 32) {
    digitalWrite(Pin24, HIGH);
#ifdef DEBUG
  Serial.println("Pin24 = on");
#endif
    butto1 = (butto1 - 32); 
  }   
  else {
    digitalWrite(Pin24, LOW);
  }   
////////////////////////////////// D25 ///////////////////////////////
  if (butto1 >= 16) {
    digitalWrite(Pin25, HIGH);
#ifdef DEBUG
  Serial.println("Pin25 = on");
#endif
    butto1 = (butto1 - 16); 
  }    
  else {
    digitalWrite(Pin25, LOW);
  }   
////////////////////////////////// D26 ///////////////////////////////
  if (butto1 >= 8) {
    digitalWrite(Pin26, HIGH);
#ifdef DEBUG
  Serial.println("Pin26 = on");
#endif 
    butto1 = (butto1 - 8);
  }    
  else {
    digitalWrite(Pin26, LOW);
  }   
////////////////////////////////// D27 ///////////////////////////////
  if (butto1 >= 4) {
    digitalWrite(Pin27, HIGH);
#ifdef DEBUG
  Serial.println("Pin27 = on");
#endif
    butto1 = (butto1 - 4); 
  }
  else {
    digitalWrite(Pin27, LOW);
  }  
////////////////////////////////// D28 ///////////////////////////////
  if (butto1 >= 2) {
    digitalWrite(Pin28, HIGH);
#ifdef DEBUG
  Serial.println("Pin28 = on");
#endif
    butto1 = (butto1 - 2); 
  } 
  else {
    digitalWrite(Pin28, LOW);
  }    
 }
}
//-------------   End of groep 2 / buttongroep 1 D22-D28   ------------//   

//-------------- Groep2 / buttongroep 2 D29->D35 -----------//
  if ( buttonin1 >= 1500 && buttonin1 <2000){
    int butto2 = buttonin1 - 1500;
    if (butto2 >=0){
#ifdef DEBUG
  Serial.print("buttongroep2 code is: ");
  Serial.println(butto2); 
#endif
////////////////////////////////// D29 ///////////////////////////////
  if (butto2 >= 128) {
    digitalWrite(Pin29, HIGH);
#ifdef DEBUG
  Serial.println("Pin29 = on");
#endif
    butto2 = (butto2 - 128); 
  }
  else {
    digitalWrite(Pin29, LOW);
  }
////////////////////////////////// D30 ///////////////////////////////
  if (butto2 >= 64) {
    digitalWrite(Pin30, HIGH);
#ifdef DEBUG
  Serial.println("Pin30 = on"); 
#endif
    butto2 = (butto2 - 64);
  }  
  else {
    digitalWrite(Pin30, LOW);
  }
///////////////////////////////// D31 ///////////////////////////////
  if (butto2 >= 32) {
    digitalWrite(Pin31, HIGH);
#ifdef DEBUG
  Serial.println("Pin31 = on");
#endif
    butto2 = (butto2 - 32); 
  }   
  else {
    digitalWrite(Pin31, LOW);
  }   
////////////////////////////////// D32 ///////////////////////////////
  if (butto2 >= 16) {
    digitalWrite(Pin32, HIGH);
#ifdef DEBUG
  Serial.println("Pin32 = on");
#endif
    butto2 = (butto2 - 16); 
  }    
  else {
    digitalWrite(Pin32, LOW);
  }   
////////////////////////////////// D33 ///////////////////////////////
  if (butto2 >= 8) {
    digitalWrite(Pin33, HIGH);
#ifdef DEBUG
  Serial.println("Pin33 = on");
#endif 
    butto2 = (butto2 - 8);
  }    
  else {
    digitalWrite(Pin33, LOW);
  }   
////////////////////////////////// D34 ///////////////////////////////
  if (butto2 >= 4) {
    digitalWrite(Pin34, HIGH);
#ifdef DEBUG
  Serial.println("Pin34 = on");
#endif
    butto2 = (butto2 - 4); 
  }
  else {
    digitalWrite(Pin34, LOW);
  }  
////////////////////////////////// D35 ///////////////////////////////
  if (butto2 >= 2) {
    digitalWrite(Pin35, HIGH);
#ifdef DEBUG
  Serial.println("Pin35 = on");
#endif
    butto2 = (butto2 - 2); 
  } 
  else {
    digitalWrite(Pin35, LOW);
  }    
 }
}
//-------------   End of groep 2 / buttongroep 2 D29-D35   ------------//   

//-------------- Groep2 / buttongroep 3 D36->D42 -----------//
  if ( buttonin1 >= 2000 && buttonin1 <2500){
    int butto3 = buttonin1 - 2000;
    if (butto3 >=0){
#ifdef DEBUG
  Serial.print("buttongroep3 code is: ");
  Serial.println(butto3); 
#endif
////////////////////////////////// D36 ///////////////////////////////
  if (butto3 >= 128) {
    digitalWrite(Pin36, HIGH);
#ifdef DEBUG
  Serial.println("Pin36 = on");
#endif
    butto3 = (butto3 - 128); 
  }
  else {
    digitalWrite(Pin36, LOW);
  }
////////////////////////////////// D37 ///////////////////////////////
  if (butto3 >= 64) {
    digitalWrite(Pin37, HIGH);
#ifdef DEBUG
  Serial.println("Pin37 = on"); 
#endif
    butto3 = (butto3 - 64);
  }  
  else {
    digitalWrite(Pin37, LOW);
  }
////////////////////////////////// D38 ///////////////////////////////
  if (butto3 >= 32) {
    digitalWrite(Pin38, HIGH);
#ifdef DEBUG
  Serial.println("Pin38 = on");
#endif
    butto3 = (butto3 - 32); 
  }   
  else {
    digitalWrite(Pin38, LOW);
  }   
////////////////////////////////// D39 ///////////////////////////////
  if (butto3 >= 16) {
    digitalWrite(Pin39, HIGH);
#ifdef DEBUG
  Serial.println("Pin39 = on");
#endif
    butto3 = (butto3 - 16); 
  }    
  else {
    digitalWrite(Pin39, LOW);
  }   
////////////////////////////////// D40 ///////////////////////////////
  if (butto3 >= 8) {
    digitalWrite(Pin40, HIGH);
#ifdef DEBUG
  Serial.println("Pin40 = on");
#endif 
    butto3 = (butto3 - 8);
  }    
  else {
    digitalWrite(Pin40, LOW);
  }   
////////////////////////////////// D41 ///////////////////////////////
  if (butto3 >= 4) {
    digitalWrite(Pin41, HIGH);
#ifdef DEBUG
  Serial.println("Pin41 = on");
#endif
    butto3 = (butto3 - 4); 
  }
  else {
    digitalWrite(Pin41, LOW);
  }  
////////////////////////////////// D42 ///////////////////////////////
  if (butto3 >= 2) {
    digitalWrite(Pin42, HIGH);
#ifdef DEBUG
  Serial.println("Pin42 = on");
#endif
    butto3 = (butto3 - 2); 
  } 
  else {
    digitalWrite(Pin42, LOW);
  }    
 }
}
//-------------   End of groep 2 / buttongroep 3 D35-D42   ------------//   

//-------------- Groep2 / buttongroep 4 D43->D49 -----------//
  if ( buttonin1 >= 2500 && buttonin1 <3000){
    int butto4 = buttonin1 - 2500;
    if (butto4 >=0){
#ifdef DEBUG
  Serial.print("buttongroep4 code is: ");
  Serial.println(butto4); 
#endif
////////////////////////////////// D43 ///////////////////////////////
  if (butto4 >= 128) {
    digitalWrite(Pin43, HIGH);
#ifdef DEBUG
  Serial.println("Pin43 = on");
#endif
    butto4 = (butto4 - 128); 
  }
  else {
    digitalWrite(Pin43, LOW);
  }
////////////////////////////////// D44 ///////////////////////////////
  if (butto4 >= 64) {
    digitalWrite(Pin44, HIGH);
#ifdef DEBUG
  Serial.println("Pin44 = on"); 
#endif
    butto4 = (butto4 - 64);
  }  
  else {
    digitalWrite(Pin44, LOW);
  }
////////////////////////////////// D45 ///////////////////////////////
  if (butto4 >= 32) {
    digitalWrite(Pin45, HIGH);
#ifdef DEBUG
  Serial.println("Pin45 = on");
#endif
    butto4 = (butto4 - 32); 
  }   
  else {
    digitalWrite(Pin45, LOW);
  }   
////////////////////////////////// D46 ///////////////////////////////
  if (butto4 >= 16) {
    digitalWrite(Pin46, HIGH);
#ifdef DEBUG
  Serial.println("Pin46 = on");
#endif
    butto4 = (butto4 - 16); 
  }    
  else {
    digitalWrite(Pin46, LOW);
  }   
////////////////////////////////// D47 ///////////////////////////////
  if (butto4 >= 8) {
    digitalWrite(Pin47, HIGH);
#ifdef DEBUG
  Serial.println("Pin47 = on");
#endif 
    butto4 = (butto4 - 8);
  }    
  else {
    digitalWrite(Pin47, LOW);
  }   
////////////////////////////////// D48 ///////////////////////////////
  if (butto4 >= 4) {
    digitalWrite(Pin48, HIGH);
#ifdef DEBUG
  Serial.println("Pin48 = on");
#endif
    butto4 = (butto4 - 4); 
  }
  else {
    digitalWrite(Pin48, LOW);
  }  
////////////////////////////////// D49 ///////////////////////////////
  if (butto4 >= 2) {
    digitalWrite(Pin49, HIGH);
#ifdef DEBUG
  Serial.println("Pin49 = on");
#endif
    butto4 = (butto4 - 2); 
  } 
  else {
    digitalWrite(Pin49, LOW);
  }    
 }
}
//-------------   End of groep 2 / buttongroep 5 A8-A14   ------------//   

//-------------- Groep2 / buttongroep 5 D43->D49 -----------//
  if ( buttonin1 >= 3000 && buttonin1 <3500){
    int butto5 = buttonin1 - 3000;
    if (butto5 >=0){
#ifdef DEBUG
  Serial.print("buttongroep5 code is: ");
  Serial.println(butto5); 
#endif
////////////////////////////////// A14 ///////////////////////////////
  if (butto5 >= 128) {
    digitalWrite(Pin14, HIGH);
#ifdef DEBUG
  Serial.println("Pin14 = on");
#endif
    butto5 = (butto5 - 128); 
  }
  else {
    digitalWrite(Pin14, LOW);
  }
////////////////////////////////// A13 ///////////////////////////////
  if (butto5 >= 64) {
    digitalWrite(Pin13, HIGH);
#ifdef DEBUG
  Serial.println("Pin13 = on"); 
#endif
    butto5 = (butto5 - 64);
  }  
  else {
    digitalWrite(Pin13, LOW);
  }
////////////////////////////////// A12 ///////////////////////////////
  if (butto5 >= 32) {
    digitalWrite(Pin12, HIGH);
#ifdef DEBUG
  Serial.println("Pin12 = on");
#endif
    butto5 = (butto5 - 32); 
  }   
  else {
    digitalWrite(Pin12, LOW);
  }   
////////////////////////////////// A11 ///////////////////////////////
  if (butto5 >= 16) {
    digitalWrite(Pin11, HIGH);
#ifdef DEBUG
  Serial.println("Pin11 = on");
#endif
    butto5 = (butto5 - 16); 
  }    
  else {
    digitalWrite(Pin11, LOW);
  }   
////////////////////////////////// A10 ///////////////////////////////
  if (butto5 >= 8) {
    digitalWrite(Pin10, HIGH);
#ifdef DEBUG
  Serial.println("Pin10 = on");
#endif 
    butto5 = (butto5 - 8);
  }    
  else {
    digitalWrite(Pin10, LOW);
  }   
////////////////////////////////// A9 ///////////////////////////////
  if (butto5 >= 4) {
    digitalWrite(Pin9, HIGH);
#ifdef DEBUG
  Serial.println("Pin9 = on");
#endif
    butto5 = (butto5 - 4); 
  }
  else {
    digitalWrite(Pin9, LOW);
  }  
////////////////////////////////// A8 ///////////////////////////////
  if (butto5 >= 2) {
    digitalWrite(Pin8, HIGH);
#ifdef DEBUG
  Serial.println("Pin8 = on");
#endif
    butto5 = (butto5 - 2); 
  } 
  else {
    digitalWrite(Pin8, LOW);
  }    
 }
}
//-------------   End of groep 2 / buttongroep 5 A8-A14   ------------//   




//-------------- Groep2 / buttongroep 6 A15 -----------//
  if ( buttonin1 >= 3500 && buttonin1 <4000){
    int butto6 = buttonin1 - 3500;
    if (butto6 >=0){
#ifdef DEBUG
  Serial.print("buttongroep6 code is: ");
  Serial.println(butto6); 
#endif
////////////////////////////////// D53 ///////////////////////////////
  if (butto6 >= 128) {
    digitalWrite(Pin15, HIGH);
#ifdef DEBUG
  Serial.println("Pin15 = on");
#endif
    butto6 = (butto6 - 128); 
  }
  else {
    digitalWrite(Pin15, LOW);
  }
 }
}
//-------------   End of groep 2 / buttongroep 5 D53   ------------//   


  } // einde functionele groep 2   

} // void loop


void expanderWrite1(byte _data ) {
Wire.beginTransmission(expander1);
Wire.send(_data);
Wire.endTransmission();
} 

void expanderWrite2(byte _data ) {
Wire.beginTransmission(expander2);
Wire.send(_data);
Wire.endTransmission();
}
Dutchraptor is online now Find More Posts by Dutchraptor
Last edited by Dutchraptor; Mar 03, 2013 at 05:27 PM.
Reply With Quote
Old Mar 03, 2013, 09:02 AM
Registered User
Deckie's Avatar
Australia, WA, Garden Island
Joined Nov 2010
415 Posts
Very nice mate, and in a short time frame. Interesting to see how you used the EEPROM. Nice work!
Deckie is offline Find More Posts by Deckie
Reply With Quote
Old Mar 04, 2013, 08:09 AM
Registered User
Joined Dec 2012
95 Posts
Dutchraptor,
I highly recommend that you follow the "Interrupt Example" further down the page of this rotary encoder tutorial: http://playground.arduino.cc/Main/RotaryEncoders

This is way more accurate than what you are doing because it uses an interrupt. Whenever the rotary encoder is turned, your main loop is interrupted and a special "interrupt" function is called to read the rotary encoder. This function will update a global variable containing the value for your channel. When this function ends, your main loop continues right where it left off. Instead of reading the rotary encoder value in your main loop, you just read the global variable.

The reason you need to do this is so that you will never miss a turn on the rotary encoder with the interrupt processing. The way you have your code right now, you'll miss turns of the rotary encoder because you are only reading it once at regular intervals. During your other processing, if somebody turns the encoder, you won't know it. That's why you need the interrupt processing.
Skystream is offline Find More Posts by Skystream
Reply With Quote
Old Mar 04, 2013, 10:21 AM
Registered User
United States, PA
Joined Feb 2013
87 Posts
Dutchraptor,

Will you post full instructions to build this once it is ready? A build thread with step by step details would help those of us who are not experienced enough to do this without instruction.

HD
Heavy_Duty is offline Find More Posts by Heavy_Duty
Reply With Quote
Old Mar 04, 2013, 11:56 AM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
270 Posts
I was planning to do that yes.
Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Old Mar 25, 2013, 11:37 AM
Registered User
tweety777's Avatar
Vlaardingen, The Netherlands
Joined Nov 2008
1,315 Posts
Is it just me or are we missing the code for actually executing commands?
Right now it seems that at best only on/off functions are executed whilst the commands for servos (the ones I need...) are just being forwarded to the next Arduino which is what I want at some point though some Arduino will need to execute the servo commands otherwise those commands are useless...

Greetings Josse
tweety777 is offline Find More Posts by tweety777
Reply With Quote
Old Mar 25, 2013, 12:25 PM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
270 Posts
Please look again or search for: Start functionele groep 1
There the servo's are being positioned to the setting which you want. It is a complete system on it's own. Digital functions and 10 servo's. All servo commands start with 1XXXX (xxxx are the subgroup and value). Don't try to use your transmitter code I gave a while ago on the newer version. There are no outputs yet for second and so on arduino's. This is a basic version.

Requirements:
RF24 library
Arduino GUI 22 or 23
2 arduino Mega (or clones)
2 NRF24L01
some 7805 for voltage control to the servo's or pots
72 10k resitors (36 for transmitter side and 36 for receiver side)

The resistor are needed for pulling the ports down so no ghost signals are send.

Danny
Dutchraptor is online now Find More Posts by Dutchraptor
Last edited by Dutchraptor; Mar 25, 2013 at 12:33 PM.
Reply With Quote
Old Mar 25, 2013, 03:47 PM
Registered User
Joined Dec 2012
95 Posts
Where are you using the resistors? You mention "ports" but I don't know what you really mean by that. Do you have a schematic per chance? Nevermind... I see the PCB layouts earlier in the thread.

The reason I ask is because the ATMEGA chip actually has built-in pull-up resistors on the digital I/O that you could utilize instead of some of your 10k resistors. All you have to do is call pinMode(2,INPUT_PULLUP); instead of pinMode(2, INPUT). This enables the built-in pull-up resistor on pin 2. That should work fine for your switches and would help to eliminate a lot of extra resistors that you don't actually need.
Skystream is offline Find More Posts by Skystream
Last edited by Skystream; Mar 25, 2013 at 03:55 PM.
Reply With Quote
Old Mar 25, 2013, 11:52 PM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
270 Posts
Skystream,
The reason I used resistors is simple. When I started the project 3 years ago, nobody at any arduino forum or modelboat forum wanted or couldn't help me. Some even said it was impossible. An old friend who died a couple of years ago, could. But he could only teach me the basic of C++ and was more of an electronics guy. The internal pull-ups didn't even occur to me before I started using them for the interpreter.

Perhaps in a second version I'm going for the internal Pull-ups. But that may take a while since I don't have a lot of time. Still need some time to finish the rotary part for the transmitter, but other little things keep coming up (like the interpreter, which is now being redone with a direct connection to the receiver channels for soundactivation with a auto setup which is more for the general public).

But then, it's an open source. Feel free to remodel/reprogram if you want and share it with us. You have more experience in this field then me. If we can make a simpler to build/use system, we all benefit. If not, you have to wait for me, until I have time. From the looks of it, it should be easy by just switching the HIGH inputs to LOW inputs and vice versa. Perhaps, but time will tell. I will look in to it, but can't give you any answer when. Could be tomorrow (probably, since I really like the idea), could be next month or even next fall/building season.

But it is a good idea to follow up, you guys have had good ideas before. The rotary for instance. And if it works, it would make building a whole lot easier.

Danny
Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Old Mar 26, 2013, 03:59 AM
GSMB Member
ken_nj's Avatar
United States, NJ, Howell
Joined Mar 2008
1,789 Posts
On the first page of this thread there were a few mentions about etching a PCB. Let me add my two cents and say I've been pretty successful doing it with overhead transparency film and an iron. A PCB laminator is a bit on the expensive side for the few boards I make.

Check out my post about it here...
http://www.rcgroups.com/forums/showthread.php?t=1360740

There is a PDF you can download and print that gives you the entire process. Hope it helps.
ken_nj is online now Find More Posts by ken_nj
Reply With Quote
Old Mar 26, 2013, 08:11 AM
---o-O-o---
blutoh's Avatar
United States, NJ, Livingston
Joined Mar 2012
1,432 Posts
Ken,

Thanks for the link, good info there. Danny also posted info earlier about the Press and Peel commercial film technique.


Danny,

Looks like the soundfx system is close to a release, so I will have time to get involved with the coding here on the Full Arduino Control System. I ordered the hardware and some accessories, it should arrive by the weekend. I have been looking thru the code and have a basic understanding of how things work. With two of us working on it, we should be able to get things done quicker .

Pete
blutoh is offline Find More Posts by blutoh
Last edited by blutoh; Mar 26, 2013 at 08:14 AM. Reason: sp.
Reply With Quote
Reply


Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
New Product Open Source Lights - Arduino based RC Light Controller LukeZ DIY Electronics 14 Apr 10, 2014 10:03 PM
Discussion Arduino Uno Based Flight Controller? alexgator Multirotor Electronics 4 Feb 15, 2013 12:49 AM
Discussion I want to auto controlled RC helicopter with arduino+wmp+nunchuk parkjungho Electric Heli Talk 3 Jun 21, 2011 02:58 PM
Discussion Arduino project to build autopilot controlled RC plane! Ecibob Electric Plane Talk 2 Apr 25, 2011 10:17 AM