HI! In order upload new data to replace the existing one in the code I want to create something like a Programming Card that I can connect trough a cable to the Arduino board and change variables with the use of a keyboard and an LCD, then store newly modified data into EEPROM. What components do I need for the "Programming Card", how could I accomplish this?
Simplest is possibly another Arduino. Do you want to use a keyboard or a keypad?
Options:
- Serial of short distance (RX to TX, TX to RX and GND).
- PS keyboard
- USB keyboard; in that case you either need a host shield or an Arduino that can act as a host. With a host shield you might also be able to communicate via USB to the other Arduino; not sure if anybody has already done that.
Your topic has been moved to a more suitable location on the forum. See the sticky topics in Uncategorized - Arduino Forum why you should not post in "Uncategorized".
I would want to use a keypad, how do I transfer data from one Arduino to another?
Your post really has the hallmarks of an X-Y problem. Please tell us what you are really doing so we can help you more effectively.
Send it. You probably want to build a value and once that value is complete send that to the other Arduino. You can have a look at Serial Input Basics - updated to get some ideas; it's for the receiving side. You can test with Serial monitor.
Next you can start writing your sender matching the choosen option in the receiver.
If the keypad and display is directly connected to the Arduino, all you need in order to change EEPROM contents, is some code to accept input from the pad/display and update the EEPROM!
If it isn't directly connected, you need to tell us exactly how it is connected. Or if you haven't made it yet, what are the requirements for the "cable" you mentioned. Length? Indoors/outdoors? etc.
I have a servo that is controlled by various calculations and conditions based on data that I need to change almost every time. The idea with the "Programming Card" is: I want to have something rectangular like a cellphone with a keypad and an LCD screen that shows the parameters and their values in order to change them, I want the said "Programming Card" to be plugged with a cable to the Arduino so I can remove it after I finished modifying the parameters.
If you’re only saving EEPROM values, it’s a lot ‘easier’.
Either add a simple UI to your code, or a serial parser to interpret the incoming commands, and update your EEPROM from there.
I have made progress this is the code by far,I need to code the keyboard and the LCD, code the EEPROM thing and then the hard part comes.Is the code ok?
#include <Adafruit_Sensor.h>
#include <Adafruit_HMC5883_U.h>
#include <Wire.h>
#include <Servo.h>
#include <EEPROM.h>
class buttonType {
private:
byte Pin;
byte State = HIGH;
byte lastState = HIGH;
unsigned long lastChange = 0;
unsigned long lastLow = 0;
unsigned long pressTime = 0;
public:
void init(byte pinNo) {
Pin = pinNo;
pinMode(Pin, INPUT_PULLUP);
}
boolean released();
unsigned long getPressTime() {
return pressTime;
}
};
boolean buttonType::released() {
byte actState = digitalRead(Pin);
if (actState != lastState) {
lastChange = millis();
lastState = actState;
}
if (State != lastState && millis() - lastChange > 30) {
State = lastState;
if (State == HIGH) {
pressTime = millis() - lastLow;
return true;
} else {
lastLow = millis();
}
}
return false;
}
Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345);
Servo EP;
Servo DT;
int TargetHeading = EEPROM.read(0);
int CurrentHeading;
int Deviation;
int Variation = 90;
int ProgrammingSwitch;
int etimer= EEPROM.read(2);
int setFlightTime = EEPROM.read(3);
int preDTAngle = EEPROM.read(4);
int DTAngle = EEPROM.read(5);
float MagDeclination = EEPROM.read(1);
unsigned long FlightTime;
unsigned long Delay;
unsigned long Delay2;
bool longPress = false;
constexpr byte buttonPin = 12;
buttonType button;
enum Mode { Programming,
Flying,
Determalisated };
Mode;
void ObtainHeading() {
sensors_event_t event;
mag.getEvent(&event);
float heading = atan2(event.magnetic.y, event.magnetic.x);
float declinationAngle = MagDeclination;
heading += declinationAngle;
if (heading < 0)
heading += 2 * PI;
if (heading > 2 * PI)
heading -= 2 * PI;
float headingDegrees = heading * 180 / M_PI;
Serial.print("Heading (degrees): ");
Serial.println(headingDegrees);
CurrentHeading = int(headingDegrees);
}
void GuidanceSystem() {
Deviation = TargetHeading - CurrentHeading;
Variation = 90 + Deviation;
constrain(Variation, 80, 110);
EP.write(Variation);
}
void Determalisation() {
if (millis() - FlightTime > setFlightTime * 60000UL) {
EP.write(90);
Delay = millis();
if (millis() - Delay > 3000UL) { DT.write(DTAngle); }
} else if (longPress) {
Mode(Determalisated);
}
}
void CheckButton() {
if (button.released()) {
if (button.getPressTime() > 200) {
longPress = true;
}
}
}
void State() {
switch (Mode) {
if(ProgrammingSwitch = 1) {
case Programming:
if (longPress) { Mode(Flying); }
break;
case Flying:
FlightTime = millis();
ObtainHeading();
GuidanceSystem();
Determalisation();
break;
case Determalisated:
Delay2 = millis();
if (millis() - Delay2 > 5000UL) { DT.write(preDTAngle); }
if (ProgrammingSwitch = 1) {
if (longPress) {
Mode(Programming);
} else if (longPress) {
Mode(Flying);
break;
default:
if (ProgrammingSwitch = 1) {
Mode(Programming);
} else {
Mode(Flying);
}
break;
}
longPress = false;
}
}
}
}
void setup() {
mag.begin();
pinMode(11, INPUT_PULLUP);
EP.attach(9);
if (etimer = 1) { DT.attach(10); }
button.init(buttonPin);
}
void loop() {
ProgrammingSwitch = digitalRead(11);
CheckButton();
State();
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.