Planning on using a keypad and an i2c adaptor as shown.
Which library would be the best for this arrangement.?
Thanks
Also wondering if there is an example either for Keypad or the interface as I could not find any in the IDE examples
Planning on using a keypad and an i2c adaptor as shown.
Which library would be the best for this arrangement.?
Thanks
Also wondering if there is an example either for Keypad or the interface as I could not find any in the IDE examples
Perhaps this will help you. I2C Libraries
The joeyoung repo looks good with examples
Yes...already did that and that's how I ended up here.
Hi,
How do you mean?
Planning on using a keypad and an i2c adaptor as shown.
What is the project?
That keypad does not need I2C comms.
google arduino keypad
google arduino I2C
Thanks.. Tom..
Thanks Tom,
I build miniature 4 stroke engines and obtaining correct size/number of valve springs always seems difficult in Aus at least.
So the project is the beginnings of the design for a winder to wind both compression and, once I get over that hurdle, eventually for extension also.
Currently do it by hand which is fine but hands don't always work like they used to and anyhow I would like to expand my learning with Arduino as well.
The way I have started to write the program, it seems there will be many button inputs to set the winder parameters and I can already see myself running out of inputs on the Uno at least.
I've seen many instances of using add-on devices through the i2c bus and thought well, why not for the switches.
So I thought perhaps the i2c and keypad (or indeed existing buttons) arrangement might be a better alternative to this allbeit having to re-write that which works so far.
Once setup, there is not a lot going on ( latter not yet written).
Watch the main spindle which is a dc motor/ gearbox drive with an encoder to give (say) 600 pulses per revolution, compare this to a pre-set pitch and advance a stepper drive on the 1.0mm pitch wire feed screw.
Note that I am aware there is some cleaning up to do ..........
#include <OneWire.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
int potVal = 0; // variable to store the Spindle Motor speed pot value
int newVal = 0; // variable to hold pot value divided by 4 to get correct range for PWM
int minSpeed = 4; // set minimum motor speed
int sw = 100; // switch delay time 500mSec
const int speedSet = A0; // pot input to set the speed of the Spindle Motor
const int speedSense = 2; // Spindle Motor speed sensor pin (interrupt)
const int Sw1 = 3; // SET lngth 1.0 (Length of Spring)
const int Sw2 = 4; // SET lngth 0.1
const int Sw3 = 5; // RE-SET lngth
const int Sw4 = 6; //SET wd(wire diameter)
const int Sw5 = 7; //RE-SET wd
const int Sw6 = 8; // SET numCoils(number of coils......EXCLUDING 2 Starter turns each end)
const int Sw7 = 9; // RE-SET numCoils
const int Sw8 = 11; // PROGRAM Switch
const int Sw9 = 12; // START button
const int motorPin = 10; // analogWrite pin for motor mosfet.........this is Spindle Drive Motor
float lngth = 0.0; // store length of the spring
int numCoils = 0; // store the number of coils on the spring
float pitch = 0.0; // store pitch of spring
float wireDia = 0.0;
//int t; // turns
//float p; // pitch of coils (feed rate eventually)
//float wd; // wire diameter
void setup() {
pinMode(Sw1, INPUT_PULLUP); // lngth 1.0....show switches as INPUTs
pinMode(Sw2, INPUT_PULLUP); // lngth 0.1
pinMode(Sw3, INPUT_PULLUP); // reset lngth
pinMode(Sw4, INPUT_PULLUP); // wd 0.1
pinMode(Sw5, INPUT_PULLUP); // reset wd
pinMode(Sw6, INPUT_PULLUP); // number coils
pinMode(Sw7, INPUT_PULLUP); // reset number coils
pinMode(Sw8, INPUT_PULLUP); // Program switch
pinMode(Sw9, INPUT_PULLUP); // START SWITCH
pinMode(speedSense, INPUT);
pinMode (motorPin, OUTPUT); // show motorPin as an OUTPUT
//Serial.begin (9600); // for testing
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(3, 0);
lcd.print( "SPRING WINDER");
lcd.setCursor(0, 2);
lcd.print(" READY to SETUP");
delay(5000);
lcd.clear();
lcd.print ("Switch on Program Sw");
lcd.setCursor(0, 2);
lcd.print(" In Next 10 Seconds");
delay(5000);
if (!digitalRead(Sw8) == 1) {
lcd.clear();
lcd.setCursor (5, 1);
lcd.print(" THANKYOU");
}
delay (5000);
progComp();
lcd.clear();
lcd.home();
lcd.print ("L = ");
//lcd.setCursor (5, 0);
lcd.print(lngth);
lcd.setCursor(0, 1);
lcd.print ("WD = ");
lcd.print(wireDia);
lcd.setCursor(0, 2);
lcd.print("Coils = ");
lcd.print(numCoils);
lcd.setCursor(14, 0);
lcd.print("IF OK");
//lcd.setCursor (12, 1);
//lcd.print ("press");
lcd.setCursor(14, 1);
lcd.print("START");
lcd.setCursor(15,2);
lcd.print("or");
lcd.setCursor(14, 3);
lcd.print("reset");
lcd.setCursor(0,3);
lcd.print ("Pitch = ");
lcd.print (pitch);
delay(5000);
while (digitalRead (Sw9) == 1) {
delay (200);
}
while (digitalRead (Sw9) == 0) {
delay (200);
lcd.clear();
lcd.setCursor(2, 1);
lcd.print("RUNNING PROGRAM");
}
}
void loop() {
motorSpeed();
}
void progComp() {
// setup dimensions for the spring
// first turn on the program enable switch before 10 second time-out period
if (!digitalRead (Sw8) == 1) { // program switch set to ENABLE sizes to be input
delay(sw);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Length =");
lcd.setCursor(0, 1);
lcd.print("Wire_Dia =");
lcd.setCursor (0, 2);
lcd.print("num_Coils = ");
lcd.setCursor(0, 3);
lcd.print("Calc_pitch = 0");
while (!digitalRead (Sw8) == 1) { // while the program switch is in the ENABLE position, allow inputs.
delay(sw);
// setup the length of the spring
if (!digitalRead (Sw1) == 1) lngth = lngth + 1; //input for lngth of the spring 1.0
delay(sw);
if (!digitalRead (Sw2) == 1) lngth = lngth + 0.1; //input for lngth of the spring 0.1
delay(sw);
lcd.setCursor(13, 0);
lcd.print(lngth, 1); // print the length of the spring
if (!digitalRead (Sw3) == 1) { // RESET to Zero lngth of the spring
delay(sw);
lngth = 0.0;
lcd.setCursor(13, 0);
lcd.print(" ");
lcd.setCursor(13, 0);
lcd.print(lngth, 1); // re-prints the zero COIL_PITCH and start again if required
}
// setup the wire diameter of the spring
if (!digitalRead (Sw4) == 1) wireDia = wireDia + 0.1; //input for the diameter of the wire
delay(sw);
lcd.setCursor (13, 1);
lcd.print(wireDia, 1); // print the WIRE_DIAMETER
if (!digitalRead(Sw5) == 1) {
wireDia = 0.0;
lcd.setCursor(13, 1);
lcd.print(" ");
lcd.setCursor(13, 1);
lcd.print(wireDia, 1);
}
// setup the number of coils of the spring
if (!digitalRead (Sw6) == 1) numCoils = numCoils + 1; // input for TURNS number
delay(sw);
lcd.setCursor(13, 2);
lcd.print(numCoils); // print the Number of TURNS
if (!digitalRead(Sw7) == 1) {
numCoils = 0;
lcd.setCursor (13, 2);
lcd.print(" ");
lcd.setCursor(13, 2);
lcd.print(numCoils);
}
// Calculate and print the "PITCH" of the Coils
if ( numCoils > 0 && wireDia > 0 && lngth > 0) {
pitch = lngth / numCoils ;
lcd.setCursor(13, 3);
lcd.print(pitch);
}
if (numCoils == 0 || lngth == 0) {
pitch = 0;
lcd.setCursor(13, 3);
lcd.print(" ");
lcd.setCursor(13, 3);
lcd.print (pitch);
}
}//End of setUp "while"
} // End of setUp "if"
//numCoils = t; // add value "t" to a meaningful name variable for later use
//Pitch = p; // add value "p" to a meaningful name variable for later use
// wireDia = wd; // add value to meaningful name variable for later use
delay (100);
}
void start() {
lcd.clear();
lcd.setCursor(7, 1);
lcd.print("RUNNING");
}
void motorSpeed() {
// set the main Spindle motor speed via Pot and PWM
potVal = analogRead(speedSet); // read and store speed pot input value
newVal = potVal / 4; // write the value /4 to get the change in range of the pot (0-1023) to analogWrite(0-255)
if (newVal < minSpeed) newVal = minSpeed; //minimum speed setting for the spindle motor
analogWrite(motorPin, newVal);
}