Ragazzi ho un problema!
Per altri progetti ho dovuto leggere la mia IMU e lo facevo con un interrupt sul pin2 della mia arduino uno, ma ora sto cercando di farlo con PinChangeInt sul pin analogico 14 o A0. C'è qualcosa che mi sfugge perchè dopo aver sputato fuori la prima rilevazione il programma si blocca. Mi aiutate?
#include <MotorNXT.h>
#include <SPI.h>
#include <math.h>
#define NO_PORTB_PINCHANGES // to indicate that port b will not be used for pin change interrupts
//#define NO_PORTC_PINCHANGES // to indicate that port c will not be used for pin change interrupts
#define NO_PORTD_PINCHANGES // to indicate that port d will not be used for pin change interrupts
//-------- define the above in your sketch, if applicable ------------------------------------------------------
#include <PinChangeInt.h>
#define PIN1 14 //voglio usare il pin A0
#define OUTPUT_READABLE_ROLLPITCHYAW
//e più in basso nel codice ho aggiunto l'isr():
// enable Arduino interrupt detection, this will execute dmpDataReady whenever there is an interrupt,
// independing on what this sketch is doing at that moment
// http://arduino.cc/en/Reference/AttachInterrupt
Serial.print("Enabling interrupt detection... ");
// attachInterrupt(interrupt, function, mode) specifies a function to call when an external interrupt occurs
pinMode(PIN1, INPUT); digitalWrite(PIN1, LOW);
PCintPort::attachInterrupt(PIN1, &dmpDataReady, RISING);
// attachInterrupt(0, dmpDataReady, RISING); // the 0 points correctly to INT0 / D2
// -> if there is an interrupt from MPU-6000 to ATMEGA328, boolean mpuInterrupt will be made true
byte mpuIntStatus = SPIread(0x3A, ChipSelPin1); // by reading INT_STATUS register, all interrupts are cleared
Serial.println("done.");
Stampa un singolo risultato, ma nn va in loop con tutte le rilevazioni...
non riesco a capire dove si trova l'errore
lesto:
ma dove si blocca il codice? la varibaile delle ISR non diventa mi true?
Ciao Lesto,
il programma stampa un solo valore della variabile x, dopo il quale esce.
A video vedo:
..............................................................
.................................................................
(tutta una serie di confugurazioni...)
DMP ready! Waiting for first data from MPU-6050...
prima di sostituire all'interrupt l'isr() il programma stampava all'infinito le singole rilevazioni;
sembra che arrivi soltanto un interrupt e dopo, qualche cosa interrompa il programma, ma non riesco a capire dove!
l'INT dell'MPU puo' essere impostato come Totem Pole o Open-Drain
Siccome tu non sai come e' impostato, tanto per non sbagliare si inseriscono le PullUp
e visto che le PullDown su Arduino non esistono, sarebbe il caso di correggere l'errore
@NXT:
la questione delle pull-down che non esistono te l'avevo già fatta presente io, hai ancora lasciato quel pezzo di codice errato nel tuo sorgente...
Ah, ho dato un'occhiata al codice, non userei un interrupt per un compito banale qual è questo:
while ((mpuInterrupt == false) && (fifoCount < packetSize))
{
// do nothing until mpuInterrupt = true or fifoCount >= 42
}
// there has just been an interrupt, so reset the interrupt flag, then get INT_STATUS byte
mpuInterrupt = false;
dove potresti cavartela con una semplice lettura della corrispondete porta logica del chip e del relativo bit
l'INT dell'MPU puo' essere impostato come Totem Pole o Open-Drain
Siccome tu non sai come e' impostato, tanto per non sbagliare si inseriscono le PullUp
e visto che le PullDown su Arduino non esistono, sarebbe il caso di correggere l'errore
// enable Arduino interrupt detection, this will execute dmpDataReady whenever there is an interrupt,
// independing on what this sketch is doing at that moment
// http://arduino.cc/en/Reference/AttachInterrupt
Serial.print("Enabling interrupt detection... ");
// attachInterrupt(interrupt, function, mode) specifies a function to call when an external interrupt occurs
pinMode(PIN1, INPUT); digitalWrite(PIN1, HIGH); //uso le pull-up
PCintPort::attachInterrupt(PIN1, &dmpDataReady, CHANGE); //prova anche FALLING
// attachInterrupt(0, dmpDataReady, RISING); // the 0 points correctly to INT0 / D2
// -> if there is an interrupt from MPU-6000 to ATMEGA328, boolean mpuInterrupt will be made true
byte mpuIntStatus = SPIread(0x3A, ChipSelPin1); // by reading INT_STATUS register, all interrupts are cleared
Serial.println("done.");
Domani nell'ora di pranzo testerò il programma e posterò la soluzione.
Grazie dell'aiuto intanto : )
leo72: @NXT:
la questione delle pull-down che non esistono te l'avevo già fatta presente io, hai ancora lasciato quel pezzo di codice errato nel tuo sorgente...
Ah, ho dato un'occhiata al codice, non userei un interrupt per un compito banale qual è questo:
while ((mpuInterrupt == false) && (fifoCount < packetSize))
{
// do nothing until mpuInterrupt = true or fifoCount >= 42
}
// there has just been an interrupt, so reset the interrupt flag, then get INT_STATUS byte
mpuInterrupt = false;
dove potresti cavartela con una semplice lettura della corrispondete porta logica del chip e del relativo bit
@Leo72 ti ringrazio dell'aiuto ma non capisco bene quello che vuoi dire: http://www.drotek.fr/shop/en/home/42-mpu6050-gyro-accelerometer.html
...with an onboard Digital Motion Processor™ (DMP™) capable of processing complex 9-axis MotionFusion algorithms.
per usare il dmp, come nel mio programma, non ho bisogno di un interrupt per capire che il buffer fifo è pieno?
INT_OPEN
When
this bit is
equal to 0, the INT pin is configured as push
pull.
When
this bit is
equal to 1, the INT pin is configured as open drain.
LATCH_INT_EN
When
this bit is
equal to 0, the INT pin emits a 50us long pulse.
W
hen
this bit is
equal to 1, the INT pin is held high until the interrupt is
cleared
l'INT dell'MPU puo' essere impostato come Totem Pole o Open-Drain
Siccome tu non sai come e' impostato, tanto per non sbagliare si inseriscono le PullUp
e visto che le PullDown su Arduino non esistono, sarebbe il caso di correggere l'errore
############# MPU-6000 Data Acquisition #############
Initializing SPI Protocol...
...SPI Protocol initializing done.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Initializing Digital Motion Processor (DMP)...
Writing DMP memory.......... done.
Verifying DMP memory.......... success!
Writing DMP configuration... done.
Verifying DMP configuration... success!
Writing DMP update 1/7 ..... done.
Verifying DMP update 1/7 ..... success!
Writing DMP update 2/7 ..... done.
Verifying DMP update 2/7 ..... success!
Writing DMP update 3/7 ..... done.
Verifying DMP update 3/7 ..... success!
Writing DMP update 4/7 ..... done.
Verifying DMP update 4/7 ..... success!
Writing DMP update 5/7 ..... done.
Verifying DMP update 5/7 ..... success!
Writing DMP update 6/7 ..... done.
Verifying DMP update 6/7 ..... success!
Writing DMP update 7/7 ..... done.
Verifying DMP update 7/7 ..... success!
... Digital Motion Processor (DMP) initializing done.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Enabling DMP... done.
Enabling interrupt detection... done.
DMP ready! Waiting for first data from MPU-6000...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Roll angle [degrees]: -2.08
Roll angle [degrees]: -2.08
Roll angle [degrees]: -2.07
Roll angle [degrees]: -2.06
Roll angle [degrees]: -2.06
Roll angle [degrees]: -2.05
Roll angle [degrees]: -2.04
Roll angle [degrees]: -2.04
Roll angle [degrees]: -2.02
Roll angle [degrees]: -2.02
Roll angle [degrees]: -2.01
Roll angle [degrees]: -2.00
Roll angle [degrees]: -1.99
Roll angle [degrees]: -1.98
Roll angle [degrees]: -1.97
Roll angle [degrees]: -1.96
Roll angle [degrees]: -1.95
Roll angle [degrees]: -1.95
Roll angle [degrees]: -1.94
Roll angle [degrees]: -1.93
Roll angle [degrees]: -1.93
Roll angle [degrees]: -1.92
Roll angle [degrees]: -1.91
@Brunello @leo72 @lesto
Grazie davvero di cuore
Lo dico col sorriso : )
[lettura dati da imu mpu6050 in spi con arduino uno]
!RISOLTO!