I'm trying to read analog pins on an Arduino Portenta H7 using the Arduino_MachineControl library. So far, I've only been able to get 3 of the analog pins to work, and, they aren't the expected pin numbers. Reading pin 0 in the code returns the value for the physical pin A3. The same applies for pins 1 and 2 in the code, returning values for physical pins A2 and A1, respectively.
#include <Arduino_MachineControl.h>
using namespace machinecontrol;
void setup() {
Serial.begin(9600);
}
void loop() {
for(int i = 0; i < 8; i++){
if(analog_in.read(i)>0){
Serial.print("Pin Requested = ");
Serial.print(i);
Serial.print(" Raw Data = ");
Serial.println(analog_in.read(i));
}
}
delay(1000);
}
Serial print from that code
07:26:56.817 -> Pin Requested = 0 Raw Data = 46890
07:26:56.817 -> Pin Requested = 1 Raw Data = 46638
07:26:56.817 -> Pin Requested = 2 Raw Data = 46555
Where Pin Requested 0, 1 and 2 each read the physical pins A3, A2 and A1 in that order. None of the other analog pins read.
I know my Portenta H7 is capable of reading the correct pins because of the analogRead example from the Arduino_PortentaBreakout library. Here is that example.
#include <Arduino_PortentaBreakout.h>
const byte ANALOG_PIN_NUMBER = 8;
const int ANALOG_RESOLUTION = 16;
// The access to each analog input is made using the peripheral silk name.
breakoutPin analogPin[] = {ANALOG_A0, ANALOG_A1, ANALOG_A2, ANALOG_A3,
ANALOG_A4, ANALOG_A5, ANALOG_A6, ANALOG_A7};
void setup() {
Serial.begin(9600);
while (!Serial);
// Max analog resolution is 16bits
Breakout.analogReadResolution(ANALOG_RESOLUTION);
}
void loop() {
// Loop through all the available inputs and print input value
for(int i = 0; i < ANALOG_PIN_NUMBER; i++) {
int w = Breakout.analogRead(analogPin[i]);
Serial.print("A");
Serial.print(i);
Serial.print(": ");
Serial.println(w);
delay(1000);
}
}
Returned values line up physical pins with pin number read correctly (analogPin[0] actually reads physical pin A0 and so forth). Here is the serial print from that code.
07:35:40.967 -> A0: 46877
07:35:41.950 -> A1: 46983
07:35:42.940 -> A2: 46829
07:35:43.974 -> A3: 46919
07:35:44.961 -> A4: 39192
07:35:45.950 -> A5: 39146
07:35:46.934 -> A6: 65535
07:35:47.963 -> A7: 25781
I tried using both the Arduino_MachineControl and Arduino_PortentaBreakout libraries, but, they won't compile together for me. I've tried Arduino IDE 1.8.19 and 2.1.1. I've also tried reinstalling the libraries. I think some of these errors might be relevant (concerning pin descriptions), but, I'm not at a level of understanding to know how to proceed. I'd like to keep using the Arduino_MachineControl library.
#include <Arduino_MachineControl.h>
#include <Arduino_PortentaBreakout.h>
void setup() {}
void loop() {}
Compiling Errors (REDACTED)
Arduino: 1.8.19 (Windows 10), Board: "Arduino Portenta H7, Main Core, 1MB M7 + 1MB M4, None"
In file included from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\libraries\PDM\src/PDM.h:23:0,
from \libraries\Arduino_PortentaBreakout\src/Arduino_PortentaBreakout.h:34,
\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/pinDefinitions.h:8:8: error: redefinition of 'struct _PinDescription'
struct _PinDescription
^~~~~~~~~~~~~~~
In file included from \libraries\Arduino_MachineControl\src/Arduino_MachineControl.h:13:0,
\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/pinDefinitions.h:8:8: note: previous definition of 'struct _PinDescription'
struct _PinDescription
^~~~~~~~~~~~~~~
In file included from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\libraries\PDM\src/PDM.h:23:0,
from \libraries\Arduino_PortentaBreakout\src/Arduino_PortentaBreakout.h:34,
\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/pinDefinitions.h:16:8: error: redefinition of 'struct _AnalogPinDescription'
struct _AnalogPinDescription
^~~~~~~~~~~~~~~~~~~~~
In file included from \libraries\Arduino_MachineControl\src/Arduino_MachineControl.h:13:0,
\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/pinDefinitions.h:16:8: note: previous definition of 'struct _AnalogPinDescription'
struct _AnalogPinDescription
^~~~~~~~~~~~~~~~~~~~~
In file included from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_rcc.h:29:0,
from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/stm32h7xx_hal_conf.h:398,
from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal.h:30,
from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/CMSIS/stm32h7xx.h:223,
from\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/cmsis.h:22,
from\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/PinNamesTypes.h:33,
from l\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\variants\PORTENTA_H7_M7/pinmode_arduino.h:24,
from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/Arduino.h:26,
from sketch\sketch_jul20b.ino.cpp:1:
\libraries\Arduino_PortentaBreakout\src/utility/Analog/Analog.h: In constructor 'BreakoutPWM::HRTIMPWMClass::HRTIMPWMClass()':
\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_rcc.h:2318:48: warning: conversion to void will not access object of type 'volatile uint32_t {aka volatile long unsigned int}'
UNUSED(tmpreg); \
\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_def.h:70:27: note: in definition of macro 'UNUSED'
#define UNUSED(x) ((void)(x))
^
\libraries\Arduino_PortentaBreakout\src/utility/Analog/Analog.h:32:9: note: in expansion of macro '__HAL_RCC_HRTIM1_CLK_ENABLE'
__HAL_RCC_HRTIM1_CLK_ENABLE();
^
\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_rcc.h:1478:48: warning: conversion to void will not access object of type 'volatile uint32_t {aka volatile long unsigned int}'
UNUSED(tmpreg); \
\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_def.h:70:27: note: in definition of macro 'UNUSED'
#define UNUSED(x) ((void)(x))
^
\libraries\Arduino_PortentaBreakout\src/utility/Analog/Analog.h:35:9: note: in expansion of macro '__HAL_RCC_GPIOG_CLK_ENABLE'
__HAL_RCC_GPIOG_CLK_ENABLE();
^
exit status 1
Error compiling for board Arduino Portenta H7.
In file included from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\libraries\PDM\src/PDM.h:23:0,
from \libraries\Arduino_PortentaBreakout\src/Arduino_PortentaBreakout.h:34,
\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/pinDefinitions.h:8:8: error: redefinition of 'struct _PinDescription'
struct _PinDescription
^~~~~~~~~~~~~~~
In file included from \libraries\Arduino_MachineControl\src/Arduino_MachineControl.h:13:0,
from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/pinDefinitions.h:8:8: note: previous definition of 'struct _PinDescription'
struct _PinDescription
^~~~~~~~~~~~~~~
In file included from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\libraries\PDM\src/PDM.h:23:0,
from \libraries\Arduino_PortentaBreakout\src/Arduino_PortentaBreakout.h:34,
l\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/pinDefinitions.h:16:8: error: redefinition of 'struct _AnalogPinDescription'
struct _AnalogPinDescription
^~~~~~~~~~~~~~~~~~~~~
In file included from \libraries\Arduino_MachineControl\src/Arduino_MachineControl.h:13:0,
\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/pinDefinitions.h:16:8: note: previous definition of 'struct _AnalogPinDescription'
struct _AnalogPinDescription
^~~~~~~~~~~~~~~~~~~~~
In file included from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_rcc.h:29:0,
from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/stm32h7xx_hal_conf.h:398,
from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal.h:30,
from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/CMSIS/stm32h7xx.h:223,
from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/cmsis.h:22,
from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/PinNamesTypes.h:33,
from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\variants\PORTENTA_H7_M7/pinmode_arduino.h:24,
from \Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/Arduino.h:26,
\libraries\Arduino_PortentaBreakout\src/utility/Analog/Analog.h: In constructor 'BreakoutPWM::HRTIMPWMClass::HRTIMPWMClass()':
\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_rcc.h:2318:48: warning: conversion to void will not access object of type 'volatile uint32_t {aka volatile long unsigned int}'
UNUSED(tmpreg); \
l\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_def.h:70:27: note: in definition of macro 'UNUSED'
#define UNUSED(x) ((void)(x))
^
\libraries\Arduino_PortentaBreakout\src/utility/Analog/Analog.h:32:9: note: in expansion of macro '__HAL_RCC_HRTIM1_CLK_ENABLE'
__HAL_RCC_HRTIM1_CLK_ENABLE();
^
\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_rcc.h:1478:48: warning: conversion to void will not access object of type 'volatile uint32_t {aka volatile long unsigned int}'
UNUSED(tmpreg); \
\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_def.h:70:27: note: in definition of macro 'UNUSED'
#define UNUSED(x) ((void)(x))
^
\libraries\Arduino_PortentaBreakout\src/utility/Analog/Analog.h:35:9: note: in expansion of macro '__HAL_RCC_GPIOG_CLK_ENABLE'
__HAL_RCC_GPIOG_CLK_ENABLE();
^
exit status 1