Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Rev 0 Created 7/7/2022 This is a limited version of Reference 1 focusing only on 4 pushbuttons - Receiver Code
- //Rev 1 Created 7/8/2022 This version of the code works with Transmitter Rev 0 to control two servo motors
- //Rev 2 Created 7/12/2022 This version of teh code works with Transmitter Rev 1 to control two servo motors. In the line RF24 radio(7,8); the 7 and 8 are changed from 8 and 9 in previous versions to free up the PWM pin that was D9 to control more servo motors
- //Rev 3 Created 7/14/2022 This is my successfull attempt to create a 12 pushbutton receiver
- //Rev 4 Created 7/16/2022 This takes the receiver from being able to control 5 servos to 6 servos. It also shifts the servo outputs to D2, D3, D4, D5, D6, D9
- //Rev 5 Created 7/20/2022 This a verion of the receiver which has 4 additional inputs (Potentiometer 1 or POT1, Pushbutton 13 or PB13, Pushbutton 14 or PB14, Pushbutton 15 or PB15). Note that POT1 uses A6 and PB13-PB15 use A7 and a resistor ladder. This corresponds to transmitter code Rev 3
- //Rev 6 Created 8/17/2022 Each time PB13 is pressed the servo angles are saved to a text file called angles. This version doesn't do anything with those saved angles yet (doesn't call the values back into the Arduino).
- //Rev 7 Created 8/18/2022 Attempt to parse saved positions back into microcontroller on startup (during the setup) - This successfully stores the SD card angles to an array with elements servo01SP[PosNt-1] thru servo06SP[PosNt-1] where the final elements of the array are at index value PosNt-1
- //Rev 8 Created 8/23/2022 Attempt to Use Saved Positions. Note it deoesn't quite do that. But it does sense PB14 being pressed and increment a counter with a pause between each press. I'm saving this state by going to Rev 9.
- //Rev 9 Created 8/23/2022 This moves the save pushbutton code and step pushbutton code (PB13 and PB14 respectively) into functions savePress and stepPress. This will make later experiments to move around the command to write to the servo motors easier
- //Note: Rev 8 & 9 appear to give the same functionality. It is just that Rev 9 unclutters void loop by moving much of the code to the savePress and stepPress function definitions
- //Rev 10 Created 8/23/2022 This is further experiments of making the stepPress code work. I wanted to save the state of Rev 9. Rev 10 moved the functions out of the radio check and added a pause inside of the readValues function to control how often the readValues function is called because without this pause the servos were moving too fast at one button press of PB1 thru PB12
- //Rev 11 Created 8/24/2022. Continuing experiments in making stepPress function code work. The modeSelect function was implemented and the various other functions were put into an if-else statement depending on the state of modeS. I wanted to save the state of Rev 11 so saved to Rev 12 for further modifications.
- //Rev 12 Created 8/24/2022. Continuing experiments in making stepPress function code work. I think my readFile function is broken. It isn't storing to the arrays properly like I thought. I should check that the functions which worked in ESP32 still work here. I will have to do more debugging.
- #include <SPI.h>
- #include <nRF24L01.h>
- #include <RF24.h>
- #include <Servo.h>
- #include <SD.h> //Used for microSD Card
- File myFile; //Used for microSD Card
- #define SIGNAL_TIMEOUT 500 // This is signal timeout in milli seconds. We will reset the data if no signal
- const int J1p=2, J2p=3, J3p=4, J4p=5, J5p=6, J6p=9; //Pins the Servo Motor Signal Wires are Attached to
- const int sdCS=A0, nrfCS=8; //SD Card Module Chip Select Pin is A0. nrfCS is NRF24 Module Chip Select which is pin D8.
- const uint64_t pipeIn = 0xF9E8F0F0E1LL;
- RF24 radio(7, nrfCS); //CE=Pin 7, CSN=Pin 8. Note: CSN is Chip Select Not or Chip Select that is active low
- unsigned long lastRecvTime = 0;
- unsigned long prevMillisRead = 0; //will store last time PB1 thru PB12 were updated
- unsigned long prevMillisPB13 = 0; //will store last time PB13 was updated
- unsigned long prevMillisStep = 0; //will store last time step pushbutton was updated
- const long intervalPB13 = 1000; //interval at which to pause after PB13 press (milliseconds)
- const long intervalStep = 1000; //interval at which to pause after step pushbutton is pressed (milliseconds)
- const long intervalRead = 25; //interval at which to pause after PB1 thru PB12 axis pushbuttons are pressed (milliseconds) - controls speed in live play mode
- int pb13Cnt=0; //Stores Number of Times PB13 has been pressed
- int pb14Cnt=0; //Stores Number of Times PB14 has been pressed
- int J1a=51, J2a=155, J3a=0, J4a=74, J5a=80, J6a=84; //Variable to Store Joint Angles i.e. Servo Motor Angles - Note: Initial values are a safe home position obtained from RxPOTRev14.ino in D:\Stuff\Projects\ESP32 Control\ServoWiFi\RxPOTRev14
- String dataMessage, Jnt1Beg="J1b", Jnt2Beg="J2b", Jnt3Beg="J3b", Jnt4Beg="J4b", Jnt5Beg="J5b", Jnt6Beg="J6b", Sbuffer; //dataMessage≡to store string to write to SD card. Jnt1 thru Jnt6≡bracket strings to enclose servo angles. J1 stands for Joint 1. J2 stands for Joint 2. The b suffix means beginning. Sbuffer≡a strong to hold one line of text
- int PosbI, PosNI, PosNd, J1bI, J2bI, J3bI, J4bI, J5bI, J6bI, PoseI; //Indexes of delimiters. PosNd≡Number of Digits in Position Number
- int PosNt, Jnt1t, Jnt2t, Jnt3t, Jnt4t, Jnt5t, Jnt6t; //t suffix≡indicates read from text file. PosN≡Position Number. Jnt≡Joint Number
- int servo01SP[50], servo02SP[50], servo03SP[50], servo04SP[50], servo05SP[50], servo06SP[50]; //Arrays used to store positions for the Saved Program Mode of the Robot
- int modeS=0; //Mode Selection Variable Used to Select Between Mode 0=Live Play from the Controller & Save Mode where Points Can Be Stored to SD Card and Mode=1 Playback Mode where Saved Positions Are Fed to the Servos
- struct PacketData
- {
- byte switch1Value;
- byte switch2Value;
- byte switch3Value;
- byte switch4Value;
- byte switch5Value;
- byte switch6Value;
- byte switch7Value;
- byte switch8Value;
- byte switch9Value;
- byte switch10Value;
- byte switch11Value;
- byte switch12Value;
- byte pot1Value;
- byte switch13Value;
- byte switch14Value;
- byte switch15Value;
- };
- PacketData receiverData;
- Servo servo1; //Pin D2
- Servo servo2; //Pin D3
- Servo servo3; //Pin D4
- Servo servo4; //Pin D5
- Servo servo5; //Pin D6
- Servo servo6; //Pin D9
- //Assign default input received values
- void setInputDefaultValues()
- {
- receiverData.switch1Value = LOW;
- receiverData.switch2Value = LOW;
- receiverData.switch3Value = LOW;
- receiverData.switch4Value = LOW;
- receiverData.switch5Value = LOW;
- receiverData.switch6Value = LOW;
- receiverData.switch7Value = LOW;
- receiverData.switch8Value = LOW;
- receiverData.switch9Value = LOW;
- receiverData.switch10Value = LOW;
- receiverData.switch11Value = LOW;
- receiverData.switch12Value = LOW;
- //Input a default value for POT1 when I decide if I want 0 or 1 digitally to be Live Play - Probably 0
- receiverData.switch13Value = LOW;
- receiverData.switch14Value = LOW;
- receiverData.switch15Value = LOW;
- }
- void readValues()
- {
- unsigned long currentReadMillis = millis(); //Records time that PB1 thru PB12 are pressed - Actually controls how often the readValues function is caused
- if (currentReadMillis - prevMillisRead >= intervalRead)
- {
- prevMillisRead = currentReadMillis; //Save the last time the readValues function was called
- //Joint 1 Angle is Controlled by Pushbutton 1 and Pushbutton 2
- if(receiverData.switch1Value==HIGH)
- {
- J1a=J1a+1; //Increments the Joint 1 Angle if Pushbutton 1 is Pressed
- }
- if(receiverData.switch2Value==HIGH)
- {
- J1a=J1a-1; //Decrements the Joint 1 Angle if Pushbutton 2 is Pressed
- }
- //Joint 2 Angle is Controlled by Pushbutton 3 and Pushbutton 4
- if(receiverData.switch3Value==HIGH)
- {
- J2a=J2a+1; //Increments the Joint 2 Angle if Pushbutton 3 is Pressed
- }
- if(receiverData.switch4Value==HIGH)
- {
- J2a=J2a-1; //Decrements the Joint 2 Angle if Pushbutton 4 is Pressed
- }
- //Joint 3 Angle is Controlled by Pushbutton 5 and Pushbutton 6
- if(receiverData.switch5Value==HIGH)
- {
- J3a=J3a+1; //Increments the Joint 3 Angle if Pushbutton 5 is Pressed
- }
- if(receiverData.switch6Value==HIGH)
- {
- J3a=J3a-1; //Decrements the Joint 3 Angle if Pushbutton 6 is Pressed
- }
- //Joint 4 Angle is Controlled by Pushbutton 7 and Pushbutton 8
- if(receiverData.switch7Value==HIGH)
- {
- J4a=J4a+1; //Increments the Joint 4 Angle if Pushbutton 7 is Pressed
- }
- if(receiverData.switch8Value==HIGH)
- {
- J4a=J4a-1; //Decrements the Joint 4 Angle if Pushbutton 8 is Pressed
- }
- //Joint 5 Angle is Controlled by Pushbutton 9 and Pushbutton 10
- if(receiverData.switch9Value==HIGH)
- {
- J5a=J5a+1; //Increments the Joint 5 Angle if Pushbutton 9 is Pressed
- }
- if(receiverData.switch10Value==HIGH)
- {
- J5a=J5a-1; //Decrements the Joint 5 Angle if Pushbutton 10 is Pressed
- }
- //Joint 6 Angle is Controlled by Pushbutton 11 and Pushbutton 12
- if(receiverData.switch11Value==HIGH)
- {
- J6a=J6a+1; //Increments the Joint 6 Angle if Pushbutton 11 is Pressed
- }
- if(receiverData.switch12Value==HIGH)
- {
- J6a=J6a-1; //Decrements the Joint 6 Angle if Pushbutton 12 is Pressed
- }
- //Now let's add limits for the range of Servo Motor Angles
- if(J1a>180)
- {
- J1a=180; //Sets the upper limit to 180
- }
- if(J1a<0)
- {
- J1a=0; //Sets the lower limit to 0
- }
- if(J2a>180)
- {
- J2a=180; //Sets the upper limit to 180
- }
- if(J2a<0)
- {
- J2a=0; //Sets the lower limit to 0
- }
- if(J3a>180)
- {
- J3a=180; //Sets the upper limit to 180
- }
- if(J3a<0)
- {
- J3a=0; //Sets the lower limit to 0
- }
- if(J4a>180)
- {
- J4a=180; //Sets the upper limit to 180
- }
- if(J4a<0)
- {
- J4a=0; //Sets the lower limit to 0
- }
- if(J5a>180)
- {
- J5a=180; //Sets the upper limit to 180
- }
- if(J5a<0)
- {
- J5a=0; //Sets the lower limit to 0
- }
- if(J6a>180)
- {
- J6a=180; //Sets the upper limit to 180
- }
- if(J6a<0)
- {
- J6a=0; //Sets the lower limit to 0
- }
- } //End of If Statement Checking to see if the apuse time has elapsed after PB1 thru PB12 are pressed
- } //End of readValue function definition
- void mapAndWriteValues(int J1a, int J2a, int J3a, int J4a, int J5a, int J6a)
- {
- servo1.write(J1a);
- servo2.write(J2a);
- servo3.write(J3a);
- servo4.write(J4a);
- servo5.write(J5a);
- servo6.write(J6a);
- } //End of mapAndWriteValues function
- void setup()
- {
- Serial.begin(115200);
- while (!Serial) {
- ; // wait for serial port to connect. Needed for native USB port only
- }
- pinMode(sdCS, OUTPUT); //SD Card Module Chip Select Pin is Made an Output
- //pinMode(sdCS, LOW); //SD Card Module Chip Select Pin is Started LOW So SD Card Module Is Initially Communicating
- //Initialize the SD Card
- Serial.print("Initializing SD card...");
- if (!SD.begin(sdCS)) //This step takes care of setting the SD Card Module Chip Select Pin Low
- {
- Serial.println("initialization failed!");
- while (1);
- }
- Serial.println("initialization done.");
- //Read the contents of the SD card
- readFile(); //Reads contents of SD card to the serial monitor once - Note: You will have to press reset on the receiver board after saving a new program to the SD card in order to run that changed program
- pinMode(sdCS, HIGH); //SD Card Module Chip Select Pin is Set High So SD Card Module Isn't Communicating Because Radio Module Needs to Communicate
- radio.begin();
- radio.setDataRate(RF24_250KBPS);
- radio.openReadingPipe(1,pipeIn);
- radio.startListening(); //start the radio receiver
- servo1.attach(J1p);
- servo2.attach(J2p);
- servo3.attach(J3p);
- servo4.attach(J4p);
- servo5.attach(J5p);
- servo6.attach(J6p);
- readValues(); //Reads the angle value initially
- setInputDefaultValues();
- mapAndWriteValues(J1a, J2a, J3a, J4a, J5a, J6a);
- } //End of void setup()
- void loop()
- {
- // Check if RF is connected and packet is available
- if(radio.isChipConnected() && radio.available())
- {
- radio.read(&receiverData, sizeof(PacketData));
- lastRecvTime = millis();
- } //End of if-statement to check if the radio signal is available
- else
- {
- //Check Signal lost.
- unsigned long now = millis();
- if ( now - lastRecvTime > SIGNAL_TIMEOUT )
- {
- setInputDefaultValues();
- //Serial.println("No Signal");
- }
- }
- modeSelect(); //Calls the modeSelect function to find out what mode the controller is in
- //Serial.println("modeS=" + String(modeS));
- if (modeS==0)
- {
- readValues(); //Reads the angles on a continual basis
- //Serial.println("J1a=" + String(J1a) + ", J2a=" + String(J2a) + ", J3a=" + String(J3a) + ", J4a=" + String(J4a) + ", J5a=" + String(J5a) + ", J6a=" + String(J6a));
- mapAndWriteValues(J1a, J2a, J3a, J4a, J5a, J6a);
- savePress(); //savePress function call which checks to see if save pushbutton has been pressed and takes action. At the time I write this as of Rev 9 the save pushbutton is PB13
- } //End of if modeS==0 i.e. end of Live Play and Save State mode
- else //if modeS==1
- {
- stepPress(); //Function call for stepPress function which checks to see if step pushbutton has been pressed and takes action. At the time I write this as of Rev 9 the step pushbutton is PB14
- //Add continuous code here later
- } //End of if modeS==1 i.e. end of step mode and continuous mode
- mapAndWriteValues(J1a, J2a, J3a, J4a, J5a, J6a);
- } //End of void loop()
- //SD Card Module Function Definitions
- // Write the integer message on the SD card
- void logSDCard(int J1a, int J2a, int J3a, int J4a, int J5a, int J6a, int pb13Cnt) {
- // dataMessage = "Posb" + String(pb13Cnt) + Jnt1Beg + String(J1a) + Jnt2Beg + String(J2a) + Jnt3Beg + String(J3a) + Jnt4Beg + String(J4a) + Jnt5Beg + String(J5a) + Jnt6Beg + String(J6a) + "Pose" + String(pb13Cnt) + "\r\n";
- dataMessage = "Posb" + String(pb13Cnt) + Jnt1Beg + String(J1a) + Jnt2Beg + String(J2a) + Jnt3Beg + String(J3a) + Jnt4Beg + String(J4a) + Jnt5Beg + String(J5a) + Jnt6Beg + String(J6a) + "Pose" + String(pb13Cnt);
- Serial.print("Save data: ");
- Serial.println(dataMessage);
- //myFile = SD.open("angles.txt", FILE_APPEND); //Note: File name should be too long or won't work
- myFile = SD.open("angles.txt", FILE_WRITE);
- myFile.seek(EOF);
- //If the file opened okay, write to it:
- if (myFile) {
- Serial.print("Writing to angles.txt...");
- myFile.println(dataMessage.c_str());
- // close the file:
- myFile.close();
- Serial.println("done.");
- } else{
- // if the file didn't open, print an error:
- Serial.println("error opening angles.txt");
- }
- }
- void readFile(){//readFile parses the contents of the angles.txt file and stores them in six arrays
- Serial.println("Reading file:");
- myFile = SD.open("angles.txt");
- if(!myFile){
- Serial.println("Failed to open file for reading");
- return;
- }
- while(myFile.available()){ //While the file is open
- //Write one line to Sbuffer
- Sbuffer = myFile.readStringUntil('\n');
- //Print to serial monitor
- // Serial.println(Sbuffer);
- PosbI = Sbuffer.indexOf("Posb");
- J1bI = Sbuffer.indexOf("J1b");
- if (J1bI==5)
- {//If the position number is a 1 digit number
- PosNI = J1bI-1; //Position Number is always 1 less than the start of J1b's index
- PosNd = 1; //1 Digit in Position Number
- }
- else if (J1bI==6)
- {//If the position number is a 2 digit number
- PosNI = J1bI-2; //Position Number is always 2 less than the start of J1b's index
- PosNd = 2; //2 Digits in Position Number
- }
- J2bI = Sbuffer.indexOf("J2b");
- J3bI = Sbuffer.indexOf("J3b");
- J4bI = Sbuffer.indexOf("J4b");
- J5bI = Sbuffer.indexOf("J5b");
- J6bI = Sbuffer.indexOf("J6b");
- PoseI = Sbuffer.indexOf("Pose");
- Serial.println(J1bI);
- Serial.print(",");
- Serial.print(J2bI);
- Serial.print(",");
- Serial.print(J3bI);
- Serial.print(",");
- Serial.print(J4bI);
- Serial.print(",");
- Serial.print(J5bI);
- Serial.print(",");
- Serial.print(J6bI);
- //Serial.println("Indices are Posb=" + String(PosbI) + ", PosN=" + String(PosNI) + ", J1b=" + String(J1bI) + ", J2b=" + String(J2bI) + ", J3b=" + String(J3bI) + ", J4b=" + String(J4bI) + ", J5b=" + String(J5bI) + ", J6b=" + String(J6bI) + ", Pose=" + String(PoseI) + ".");
- PosNt = Sbuffer.substring(PosNI, PosNI+PosNd).toInt(); //Parses out the position number
- Jnt1t = Sbuffer.substring(J1bI+3, J2bI).toInt(); //Parses out the Joint 1 Angle
- Jnt2t = Sbuffer.substring(J2bI+3, J3bI).toInt(); //Parses out the Joint 2 Angle
- Jnt3t = Sbuffer.substring(J3bI+3, J4bI).toInt(); //Parses out the Joint 3 Angle
- Jnt4t = Sbuffer.substring(J4bI+3, J5bI).toInt(); //Parses out the Joint 4 Angle
- Jnt5t = Sbuffer.substring(J5bI+3, J6bI).toInt(); //Parses out the Joint 5 Angle
- Jnt6t = Sbuffer.substring(J6bI+3, PoseI).toInt(); //Parses out the Joint 6 Angle
- //Serial.println(String(PosNt) + "," + String(Jnt1t) + "," + String(Jnt2t) + "," + String(Jnt3t) + "," + String(Jnt4t) + "," + String(Jnt5t) + "," + String(Jnt6t)); //This is purely a debug line
- //Store angles read from text file to arrays
- servo01SP[PosNt-1] = Jnt1t; //Store current Joint 1 Angle to Element of servo01SP array. PosNT-1 is minus 1 because servo01SP array starts at index 0 but position numbers start at 1
- servo02SP[PosNt-1] = Jnt2t; //Store current Joint 2 Angle to Element of servo02SP array. PosNT-1 is minus 1 because servo02SP array starts at index 0 but position numbers start at 1
- servo03SP[PosNt-1] = Jnt3t; //Store current Joint 3 Angle to Element of servo03SP array. PosNT-1 is minus 1 because servo03SP array starts at index 0 but position numbers start at 1
- servo04SP[PosNt-1] = Jnt4t; //Store current Joint 4 Angle to Element of servo04SP array. PosNT-1 is minus 1 because servo04SP array starts at index 0 but position numbers start at 1
- servo05SP[PosNt-1] = Jnt5t; //Store current Joint 5 Angle to Element of servo05SP array. PosNT-1 is minus 1 because servo05SP array starts at index 0 but position numbers start at 1
- servo06SP[PosNt-1] = Jnt6t; //Store current Joint 6 Angle to Element of servo06SP array. PosNT-1 is minus 1 because servo06SP array starts at index 0 but position numbers start at 1
- //The following section is for debugging to make sure that the array elements stored correctly - Change the number in servo06SPst and servo06SP in all 3 instances in the following lines only to each of the array elements to test one by one. Note: The following lines are commented out because they are only for debugging purposes
- //String servo06SPst=String(servo06SP[PosNt-1]); //Converts Array Element to String - Do not try to do the conversion of an array element to string inside of the Serial.print function because the text file will not open
- //Serial.println("Success Position" + String(PosNt) + "," + servo06SPst); //Must verify array storage one element at a time
- } //End of while myFile.available() loop
- myFile.close();
- } //End of readFile function definition
- void savePress(){//savePress checks to see if the save pushbutton has been pressed and takes action to store the positions on the micro SD card
- if (receiverData.switch13Value == 1) //If PB13 is Pressed
- {
- unsigned long currentPB13Millis = millis(); //Records time that PB13 is pressed
- if (currentPB13Millis - prevMillisPB13 >= intervalPB13) { //Check to see if intervalPB13 has passed/elapsed
- prevMillisPB13 = currentPB13Millis; //Save the last time you blinked the LED
- pb13Cnt++; //Increment the PB13 Counter
- //digitalWrite(nrfCS, HIGH); //This is active low. So by turning the Radio Module Chip Select Pin High the communication between Radio Module and Microcontroller is Stopped
- radio.stopListening(); //stop the radio receiver
- //Initialize the SD Card
- Serial.print("Initializing SD card...");
- if (!SD.begin(sdCS))
- {
- Serial.println("initialization failed!");
- while (1);
- }
- Serial.println("initialization done.");
- logSDCard(J1a, J2a, J3a, J4a, J5a, J6a, pb13Cnt); //Function Call to Log Angles to SD Card
- digitalWrite(sdCS, HIGH); //This is active low. So by turning the SD Card Module Chip Select Pin High the communication between SD Card Module and Microcontroller is Stopped
- radio.startListening(); //start the radio receiver
- //digitalWrite(nrfCS, LOW); //This is active low. So by turning the Radio Module Chip Select Pin LOW the communication between Radio Module and Microcontroller is Restarted
- } //End of If Statement Checking if Pushbutton Pause Interval has passed
- } //End of If Statement for if PB13 is Pressed
- } //End of the savePress function definition
- void stepPress(){//stepPress checks to see if the step pushbutton has been pressed and takes action to step through the stored positions
- if (receiverData.switch14Value == 1) //If PB14 is Pressed
- {
- unsigned long currentStepMillis = millis(); //Records time that Step Pushbutton is pressed
- if (currentStepMillis - prevMillisStep >= intervalStep)
- { //Check to see if intervalStep has passed/elapsed
- prevMillisStep = currentStepMillis; //Save the last time you pressed the pushbutton
- //Stepping Code
- int serv1 = servo01SP[pb14Cnt];
- int serv2 = servo02SP[pb14Cnt];
- int serv3 = servo03SP[pb14Cnt];
- int serv4 = servo04SP[pb14Cnt];
- int serv5 = servo05SP[pb14Cnt];
- int serv6 = servo06SP[pb14Cnt];
- //radio.stopListening(); //stop the radio receiver
- //digitalWrite(sdCS, HIGH); //This is active low. So by turning the SD Card Module Chip Select Pin High the communication between SD Card Module and Microcontroller is Stopped
- servo1.write(serv1);
- servo2.write(serv2);
- servo3.write(serv3);
- //servo4.write(serv4);
- //servo5.write(serv5);
- //servo6.write(serv6);
- //radio.startListening(); //start the radio receiver
- pb14Cnt++;
- Serial.println("PB14 Pressed " + String(pb14Cnt) + " times." + String(serv1) + String(serv2) + String(serv3)); //A debug line just to make sure the PB14 press code works
- } //End of if statement checking to see if the pause time has elasped
- } //End of If Statement for if PB14 is Pressed
- } //End of stepPress function definition
- int modeSelect()
- {
- int modePOT = receiverData.pot1Value; //Reads the mode selection potentiometer and stores to modePOT variable
- //Serial.println("modePOT=" + String(modePOT));
- if(modePOT < 127)
- {
- modeS=0;
- }
- else
- {
- modeS=1;
- }
- return modeS;
- }
- //References
- //Reference 1- Adaptation of https://www.youtube.com/watch?v=gsHeNrDoK84&t=14s which is the "Hash Include Electronics" YouTube channel video "Arduino 10 Channels Wireless Transmitter Receiver | nrf24l01+| DIY" File Located at https://github.com/un0038998/10_Channel_NRF_Transmitter_Receiver
- //Reference 2- Used for Servo Motor Angle from Pushbutton funcionality https://www.youtube.com/watch?v=fxgcnJJlTd4&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=41&t=39s - Paul McWhorter Video Arduino Tutorial 40: Controlling DC Motor Speed and Direction with Pushbuttons
- //Reference 3- Learning How to Use Multiple SPI Devices (micro SD card module with NRF24) http://www.learningaboutelectronics.com/Articles/Multiple-SPI-devices-to-an-arduino-microcontroller.php
- //Reference 4- Learning How to Use micro SD Card Module with Arduino https://dronebotworkshop.com/sd-card-arduino/ and https://randomnerdtutorials.com/guide-to-sd-card-module-with-arduino/
- //Reference 4- For putting a pause once Pushbutton 13 is pressed before it will read again - Blink without Delay https://create.arduino.cc/example/builtin/02.Digital%5CBlinkWithoutDelay/BlinkWithoutDelay/preview
- //Reference 5- For being able to Append onto a File in the micro SD card module the comment by André Carvalho https://arduino.stackexchange.com/questions/65888/arduino-sd-card-open-file-modes-append-overwrite
- //Notes on Pinouts
- //On Arduino Nano NRF24 Breakout Board Pin SCK goes to D13. On Arduino Mega NRF24 Breakout Board Pin SCK goes to D52 which is the SCK on the Mega.
- //On Arduino Nano NRF24 Breakout Board Pin MO goes to D11. On Arduino Mega NRF24 Breakout Board Pin MO goes to D51 which is the MOSI on the Mega.
- //On Arduino Nano NRF24 Breakout Board Pin MI goes to D12. On Arduino Mega NRF24 Breakout Board Pin MI goes to D50 which is the MISO on the Mega.
- //On Arduino Nano NRF24 Breakout Board Pin CE goes to D7. On Arduino Mega NRF24 Breakout Board Pin CE goes to D7 which is nothing special on the Mega (this pin is not required to be PWM). Can also use D40 on the Mega
- //On Arduino Nano NRF24 Breakout Board Pin CSN goes to D8. On Arduino Mega NRF24 Breakout Board Pin CSN goes to D8 which needs to be a PWM pin on the Mega (it is). - Note doesn't actually need to be PWM. Can also use D41 on the Mega
- //Reference 4
- //You only need to open the file with FILE_WRITE and use file.seek(EOF) to go to de end of the file. After that you can write whatever you want that will be appended to the end of the file.
- //File outputFile = SD.open(LOG_FILE, FILE_WRITE);
- //outputFile.seek(EOF);
- //outputFile.println("Appended to the EOF");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement