Hi folks. I am trying to run GPS+Rotary encoder on Portenta H7 Lite with breakout, but I can not register any movement from the encoder. What am I doing wrong?
#include <Arduino_PortentaBreakout.h>
#include <TinyGPSPlus.h>
//breakoutPin pwmPins[] = {PWM0, PWM1, PWM2, PWM3, PWM4 , PWM5, PWM6 , PWM7, PWM8, PWM9};
//breakoutPin analogPins[] = {ANALOG_A0, ANALOG_A1, ANALOG_A2, ANALOG_A3, ANALOG_A4, ANALOG_A5, ANALOG_A6, ANALOG_A7};
#define rtEncdrPinA GPIO_0 //Pins used by Encoder
#define rtEncdrPinB GPIO_1
volatile long etEncdrPos = 0; //Encoder possition
static const uint32_t GPSBaud = 9600; //GPS baud rate
TinyGPSPlus gps; // The TinyGPSPlus object creation
struct GPSsensorData {
float StrLatitude;
float StrLongitude;
float StrhDOP;
float StrCourse;
float StrSpeed;
byte StrnumberSat;
float Deviation;
};
GPSsensorData GPSreadings; //GPSsensorData от тип GPSreadings декларирано по-горе.
void setup()
{
Serial.begin(9600);
Breakout.UART0.begin(GPSBaud); //Активация на Уарт0 където е свързан ГПС.
pinMode(rtEncdrPinA, INPUT_PULLUP); // why Input_PullUP ->https://www.youtube.com/watch?v=jJnD6LdGmUo
pinMode(rtEncdrPinB, INPUT_PULLUP);
attachInterrupt(0, rotatorMeasurment, RISING); //interrupt arduino with the function rotatorMeasurment using RISING to trigger when the pin goes from low to high
}
void loop()
{
GPSMeasure();
StructPrint();
GPSreadings.Deviation = etEncdrPos;
smartDelay(500); // delay + feeding the GPS data into Arduino
}
// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (Breakout.UART0.available())
gps.encode(Breakout.UART0.read());
}
while (millis() - start < ms);
}
void GPSMeasure() { // take GPS measurments
GPSreadings.StrLatitude = gps.location.lat();
GPSreadings.StrLongitude = gps.location.lng();
GPSreadings.StrhDOP = gps.hdop.hdop();
GPSreadings.StrCourse = gps.course.deg();
GPSreadings.StrSpeed = gps.speed.kmph();
GPSreadings.StrnumberSat = (int)gps.satellites.value();
if (millis() > 5000 && gps.charsProcessed() < 10)
Serial.println(F("No GPS data received: check wiring"));
}
void rotatorMeasurment()
{
if (digitalRead(rtEncdrPinA) == digitalRead(rtEncdrPinB)) {
etEncdrPos++;
} else {
etEncdrPos--;
}
if (etEncdrPos >= 360) {
etEncdrPos = etEncdrPos - 360;
}
if (etEncdrPos < 0) {
etEncdrPos = etEncdrPos + 360;
}
}
void StructPrint()
{
Serial.print ("Recieved Latitude: ");
Serial.println (GPSreadings.StrLatitude);
Serial.print ("Recieved Longitude: ");
Serial.println (GPSreadings.StrLongitude);
Serial.print ("Recieved HDOP: ");
Serial.println (GPSreadings.StrhDOP);
Serial.print ("Recieved Course: ");
Serial.println (GPSreadings.StrCourse);
Serial.print ("Recieved Speed: ");
Serial.println (GPSreadings.StrSpeed);
Serial.print ("Recieved number of satellites: ");
Serial.println (GPSreadings.StrnumberSat);
Serial.print("Deviation: ");
Serial.println(GPSreadings.Deviation);
}