AccelStepperI2C
v 0.1
I2C wrapper (and a bit more) for the AccelStepper Arduino library
Change_address.ino
Go to the documentation of this file.
1
/*
2
AccelStepperI2C - Change I2C address demo
3
(c) juh 2022
4
5
Test and demonstrate changing the I2C address permanently.
6
Just I2C-connect any slave device with the AccelStepperI2C firmware
7
and flash this demo to the master.
8
9
*/
10
11
12
#include <Arduino.h>
13
#include <
I2Cwrapper.h
>
14
#include <Wire.h>
15
16
const
uint8_t
oldAddress
= 0x08;
17
const
uint8_t
newAddress
= 0x07;
18
const
int
me
= 2500;
// delay between steps
19
20
I2Cwrapper
wrapper
(
oldAddress
);
21
I2Cwrapper
wrapperNew
(
newAddress
);
22
23
24
void
setup
()
25
{
26
27
Wire.begin();
28
Serial.begin(115200);
29
while
(!Serial) {}
30
31
Serial.println(
"\n\n\nAccelStepperI2C change I2C address demo\n\n"
);
32
delay(
me
);
33
34
Serial.println(
"Trying to reach slave at old address..."
);
35
delay(
me
);
36
37
if
(
wrapper
.
ping
()) {
// is slave present at old oldAddress?
38
39
Serial.print(
"Slave found at old address "
); Serial.println(
oldAddress
);
40
delay(
me
);
41
42
Serial.print(
"\nChanging address to "
); Serial.println(
newAddress
);
43
wrapper
.
changeI2Caddress
(
newAddress
);
44
delay(
me
);
45
46
Serial.println(
"\nAddress changed. Rebooting slave....\n"
);
47
wrapper
.
reset
();
48
delay(
me
);
49
50
// From here on we'll need to use the wrapperNew object, as the wrapper object is still bound to the old address
51
52
Serial.println(
"Trying to reach slave at new address...\n"
);
53
delay(
me
);
54
55
if
(
wrapperNew
.
ping
()) {
56
57
Serial.print(
"Slave successfully found at new address "
);
58
Serial.print(
newAddress
); Serial.println(
"!\n\n"
);
59
delay(
me
);
60
61
Serial.println(
"Changing back to old address and rebooting...\n"
);
62
wrapperNew
.
changeI2Caddress
(
oldAddress
);
63
wrapperNew
.
reset
();
64
delay(
me
);
65
66
// and back to using the old wrapper object, again.
67
68
if
(
wrapper
.
ping
()) {
69
Serial.println(
"Successfully changed back to old address."
);
70
}
else
{
71
Serial.println(
"Sorry, could not change back to old address."
);
72
}
73
}
else
{
74
Serial.print(
"Slave *not* found at new address "
);
75
Serial.print(
newAddress
); Serial.println(
", something went wrong"
);
76
}
77
}
else
{
78
Serial.print(
"Slave not found at old address "
);
79
Serial.print(
oldAddress
); Serial.println(
", please check your connections and reboot."
);
80
}
81
Serial.println(
"\n\nFinished."
);
82
}
83
84
void
loop
()
85
{
86
}
setup
void setup()
Definition:
Change_address.ino:24
I2Cwrapper
A helper class for the AccelStepperI2C (and ServoI2C) library.
Definition:
I2Cwrapper.h:79
me
const int me
Definition:
Change_address.ino:18
I2Cwrapper.h
A helper class for the AccelStepperI2C (and ServoI2C) library.
loop
void loop()
Definition:
Change_address.ino:84
oldAddress
const uint8_t oldAddress
Definition:
Change_address.ino:16
wrapperNew
I2Cwrapper wrapperNew(newAddress)
I2Cwrapper::ping
bool ping()
Test if slave is listening.
Definition:
I2Cwrapper.cpp:102
I2Cwrapper::changeI2Caddress
void changeI2Caddress(uint8_t newAddress)
Permanently change the I2C address of the device. New address is stored in EEPROM (AVR) or flash memo...
Definition:
I2Cwrapper.cpp:114
newAddress
const uint8_t newAddress
Definition:
Change_address.ino:17
wrapper
I2Cwrapper wrapper(oldAddress)
Definition:
Interrupt_Endstop.ino:43
I2Cwrapper::reset
void reset()
Tells the slave to reset to it's default state. It is recommended to reset the slave every time the m...
Definition:
I2Cwrapper.cpp:108
AccelStepperI2C
examples
Change_address
Change_address.ino
Generated on Fri Feb 25 2022 18:36:30 for AccelStepperI2C by
1.8.17