ecco il circuito, e ora arriva il codice
// Arduino analog input 5 - I2C SCL
// Arduino analog input 4 - I2C SDA
#include <Wire.h>
// I2C device address is 0 1 0 0 A2 A1 A0
#define GPIO1 (0x20)
#define GPIO2 (0x27)
byte motion[]={0xA,0x6,0x5,0x9};
byte bits = 0x00;
void setup() {
Serial.begin(9600);
//Serial.println(DIP_ADDRESS); delay(2000);
Wire.begin();
gpio_write(GPIO2, 0xffff,0);
gpio_dir(GPIO2, 0x0000);
}
void loop() {
for(int i =0; i<4;i++){
bits = motion[i] << 4 || motion[i];
gpio_write(GPIO2, bits, 1);
Serial.println(bits);
delay(100);
}
}
#define REGISTER_INPUT (0)
#define REGISTER_OUTPUT_0 (2)
#define REGISTER_OUTPUT_1 (3)
#define REGISTER_CONFIG (6)
//funzione che legge i bit di un determinato IC
int gpio_read(int address) {
int data = 0;
// Send input register address
Wire.beginTransmission(address);
Wire.send(REGISTER_INPUT);
Wire.endTransmission();
// Connect to device and request two bytes
Wire.beginTransmission(address);
Wire.requestFrom(address, 2);
if (Wire.available()) {
data = Wire.receive();
}
if (Wire.available()) {
data |= Wire.receive() << 8;
}
Wire.endTransmission();
return data;
}
//funzione che setta il chip di indirizzo address nel modo dir (dir è il control register)
void gpio_dir(int address, int dir) {
// Send config register address
Wire.beginTransmission(address);
Wire.send(REGISTER_CONFIG);
// Connect to device and send two bytes
Wire.send(0xff & dir); // low byte
Wire.send(dir >> 8); // high byte
Wire.endTransmission();
}
//funzione che setta i bit di un determinato IC
void gpio_write(int address, int data, int port) {
if(port == 0){
// Send output register address
Wire.beginTransmission(address);
Wire.send(REGISTER_OUTPUT_0);
// Connect to device and send two bytes
Wire.send(0xff & data); // low byte
Wire.send(data >> 8); // high byte
Wire.endTransmission();
}
if(port == 1){
// Send output register address
Wire.beginTransmission(address);
Wire.send(REGISTER_OUTPUT_1);
// Connect to device and send two bytes
Wire.send(0xff & data); // low byte
Wire.send(data >> 8); // high byte
Wire.endTransmission();
}
else Serial.print("cazzone");
}
Il problema è questo:
se io metto dentro il for
bits = motion << 4; il primo motore si muove se metto
bits = motion << 4 || motion; oppure bits = motion << 4 | motion*; non si muove più nessuno.*
l'idea è avere la sequenza che fa muovere uno stepper in un array, io vado a prelevare i dati di questo e scrivo i 4 MSB e i 4LSB in una variabile bits. in questo modo decido la direzione dello stepper.
La corrente dovrebbe arrivare giusta perchè alimento con il mio alimentatore ATX (c'ho messo pure un neon da scanner :D).
Boh, avete qualche idea?