hey, guys. zz cat here. =^/.^=
so, i've got idea i'm usin' uno read values off pot, send micro down i2c bus & micro converts value signal pulse attached servo.
so! problem: twitching.
i've checked serial monitor & it's goin' 0 44 & looping through that, despite figure being mapped 0-1023 0-179.
the first code document master transmitter i've written arduino uno:
the second code document slave receiver i've written arduino micro:
first screenie bottom end. ie when pot @ it's lowest point:
second screenie "top end" when turn pot 1/8 of way up:
third & final screenie: here's happens if turn pot higher up...
so, that's suspect causing twitching. question is... can fix this?
so, i've got idea i'm usin' uno read values off pot, send micro down i2c bus & micro converts value signal pulse attached servo.
so! problem: twitching.
i've checked serial monitor & it's goin' 0 44 & looping through that, despite figure being mapped 0-1023 0-179.
the first code document master transmitter i've written arduino uno:
code: [select]
/*
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
////////////////////////////////////////\/
/\ arduino i2c servo controller(master) \/
/\ v1.0.0 \/
/\ \/
/\ designed by: \/
/\ cudby Æronautics international \/
/\////////////////////////////////////////
/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
description:
i2c serial-based servo controller using arduino's uno & micro. uno configured master/writer & micro configured slave/receiver.
uno converts analog values of attached pot serial value & transmits value micro. micro converts received serial value pwm signal
turn servo according position of potentiometer that's attached uno.
the circuit:
uno:
> either powered usb lead or vin jack.
> leg 1 of pot connected a0 & pulled high.
> leg 2 of pot connected a1 & analog values read pin.
> leg 3 of pot connected a2 & pulled low.
> a4 (uno) connected d2 (micro) 4k7 pull-up resistor on sda bus line.
> a5 (uno) connected d3 (micro) 4k7 pull-up resistor on scl bus line.
micro:
> powered usb lead.
> d2 (micro) connected a4 (uno).
> d3 (micro) connected a5 (uno.
> d4 connected sig lead of servo.
> + lead of servo connected 5v pin.
> - lead of servo connected gnd pin.
*/
// libraries:
#include <wire.h> // add use of i2c library. #hashtagsaregay
// digital i/o pins:
const int pothighpin = a0; // leg 1 of pot connected adc0.
const int potlowpin = a2; // leg 3 of pot connected adc2.
// adc pin:
const int potwiperpin = a1; // leg 2 of pot connected adc1.
void setup() {
serial.begin(9600); // start serial monitor @ 9600baud.
wire.begin(); // start i2c bus. address not needed master device.
// pot properties:
pinmode(pothighpin, output); // configure leg 1 of pot output.
pinmode(potlowpin, output); // configure leg 3 of pot output.
digitalwrite(pothighpin, high); // drive leg 1 of pot high.
digitalwrite(potlowpin, low); // drive leg 3 of pot low.
}
void loop() {
byte swep = analogread(potwiperpin); // read wiper position analog value.
wire.begintransmission(4); // transmit device #4.
wire.write(swep); // send 4 bytes.
wire.endtransmission(); // stop transmitting.
}
the second code document slave receiver i've written arduino micro:
code: [select]
/*
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
////////////////////////////////////////\/
/\ arduino i2c servo controller (slave) \/
/\ v1.0.0 \/
/\ \/
/\ designed by: \/
/\ cudby Æronautics international \/
/\////////////////////////////////////////
/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
description:
i2c serial-based servo controller using arduino's uno & micro. uno configured master/writer & micro configured slave/receiver.
uno converts analog values of attached pot serial value & transmits value micro. micro converts received serial value pwm signal
turn servo according position of potentiometer that's attached uno.
the circuit:
uno:
> either powered usb lead or vin jack.
> leg 1 of pot connected a0 & pulled high.
> leg 2 of pot connected a1 & analog values read pin.
> leg 3 of pot connected a2 & pulled low.
> a4 (uno) connected d2 (micro) 4k7 pull-up resistor on sda bus line.
> a5 (uno) connected d3 (micro) 4k7 pull-up resistor on scl bus line.
micro:
> powered usb lead.
> d2 (micro) connected a4 (uno).
> d3 (micro) connected a5 (uno.
> d4 connected sig lead of servo.
> + lead of servo connected 5v pin.
> - lead of servo connected gnd pin.
*/
// libraries:
#include <servo.h> // add use of servo library.
#include <wire.h> // add use of i2c library. #hashtagsaregay
// servos:
servo not_a_servo; // create servo called "not servo."
void setup() {
serial.begin(9600); // start serial monitor @ 9600baud.
wire.begin(4); // start i2c bus device #4.
wire.onreceive(receiveevent); // register event.
not_a_servo.attach(4); // attach sig lead d4.
}
void loop() {
}
void receiveevent(int range) {
if (wire.available()) { // if there's data available @ i2c port...
int swep = wire.read(); // read received data integer.
swep = map(swep, 0, 1023, 0, 180); // map recieved data sweep range.
not_a_servo.write(swep); // turn servo horn according recieved data.
serial.println(swep); // transmit sweep angle serial monitor.
}
}
first screenie bottom end. ie when pot @ it's lowest point:
second screenie "top end" when turn pot 1/8 of way up:
third & final screenie: here's happens if turn pot higher up...
so, that's suspect causing twitching. question is... can fix this?
what "screenie"s?
why isn't int?
byte swep = analogread(potwiperpin); // read wiper position analog value.
how send 4 bytes?
wire.write(swep); // send 4 bytes.
swep 1 byte
on receive side
swep = map(swep, 0, 1023, 0, 180); // map recieved data sweep range.
how can 1023 come in when said swep byte (0-255) in original read?
why isn't int?
byte swep = analogread(potwiperpin); // read wiper position analog value.
how send 4 bytes?
wire.write(swep); // send 4 bytes.
swep 1 byte
on receive side
swep = map(swep, 0, 1023, 0, 180); // map recieved data sweep range.
how can 1023 come in when said swep byte (0-255) in original read?
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > I2C: UNO Master, Micro Slave & servo trouble.
arduino
Comments
Post a Comment