Salve a tutti.
Sono nuovo in questo campo e spero che qualcuno mi aiuti in questo problema.
Ho appena acquistato un Adafruit Motor Shield v2.3 e vorrei utilizzarlo su un Arduino Uno R4 WiFi.
Per quanto riguarda i collegamenti ho eseguito i seguenti passi:
ho tolto il VIN jumper
per ora sto utilizzando due batterie 3.7V per limentare il motor shield
il mio arduino è collegato al pc con un cavo usb
ho collegato un motore DC in M1.
Ho provato ad eseguire il codice di esempio:
#include <Adafruit_MotorShield.h>
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
// You can also make another motor on port M2
//Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Adafruit Motorshield v2 - DC Motor test!");
if (!AFMS.begin()) { // create with the default frequency 1.6KHz
// if (!AFMS.begin(1000)) { // OR with a different frequency, say 1KHz
Serial.println("Could not find Motor Shield. Check wiring.");
while (1);
}
Serial.println("Motor Shield found.");
// Set the speed to start, from 0 (off) to 255 (max speed)
myMotor->setSpeed(150);
myMotor->run(FORWARD);
// turn on motor
myMotor->run(RELEASE);
}
void loop() {
uint8_t i;
Serial.print("tick");
myMotor->run(FORWARD);
for (i=0; i<255; i++) {
myMotor->setSpeed(i);
delay(10);
}
for (i=255; i!=0; i--) {
myMotor->setSpeed(i);
delay(10);
}
Serial.print("tock");
myMotor->run(BACKWARD);
for (i=0; i<255; i++) {
myMotor->setSpeed(i);
delay(10);
}
for (i=255; i!=0; i--) {
myMotor->setSpeed(i);
delay(10);
}
Serial.print("tech");
myMotor->run(RELEASE);
delay(1000);
}
Il problema è che AFMS.begin() mi restituisce False (quindi sul monitor seriale viene stampato "Could not find Motor Shield. Check wiring.").
Ho provato a fare un'analisi più approfondita, cercando di capire se almeno l'Arduino riuscisse a riconoscere un dispositivo I2C. Ho caricato uno sketch di scansione I2C per cercare di rilevare gli indirizzi I2C dei dispositivi connessi all'Arduino e l'arduino non ha rilevato nessun dispositivo I2C.
Intanto ... hai seguito ALLA LETTERA quanto descritto nel loro tutorial QUI?
Per il resto, guardando lo schema, non vedo particolari criticità ... utilizza i classici pin per il bus I2C, pin che sono uguali alla UNO R3 anche sulla R4 WiFi (che, in più, ha anche un secondo bus I2C, ma esclusivamente a 3.3V sul piccolo connettore JST che è sul lato).
Lascia solo le alimentazioni, null'altro collegato ed effettua la scansione del bus I2C:
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, November 27, 2015.
// Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
#include <Wire.h>
void setup()
{
Wire.begin();
delay(1000);
Serial.begin(9600);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknow error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
Non so se può esserle d'aiuto però ho fatto questa prova.
Ho tolto la shield dall'arduino e ho provato ad utilizzare un modulo che utilizzasse il protocollo I2C (in particolare l'HW-084, però questo non è importante).
Il modulo l'ho collegato sui pin SDA ed SCL dell'arduino.
Ho eseguito il codice che mi ha inviato prima, e questo viene riconosciuto.
Successivamente, ho ricollegato la shield sull'arduino e ho provato a collegare l'HW-084 sui pin SDA ed SCL della shield. In questo caso non viene riconosciuto.
Un'ulteriore cosa che ho notato è che il codice che mi ha inviato è stato eseguito velocemente (quasi istantaneo) nel primo caso (il caso in cui la shield era scollegata).
Nel secondo caso, invece (la shield era inserita) per ogni ciclo del for:
for(address = 1; address < 127; address++ )
il codice impiegava almeno un secondo.
Quindi per controllare tutti gli indirizzi l'arduino impiegava circa due minuti.