I have written a simple script to get angle measurements from a magnetic sensor. The script works very well on Windows. However, when compiling the script on a Linux VirtualBox (Ubuntu 20.04), the sensor repeats the first angle reading and does not change from this, despite the angle changing. There are no errors/warnings given by Windows or Linux at any stage of compiling/uploading.
Uploading the script on Windows and then viewing in Linux serial monitor works. However, uploading it on Linux and then viewing in Windows serial monitor does not work ("Board is not available"), even when connecting the board to Linux and not Windows.
I've compared both systems and everything seems to be the same: the same Arduino Uno R3 board, Arduino IDE 1.8.19 on both systems, Arduino AVR Boards 1.8.3 on both, "Arduino Uno" selected as the board on both, the library is SimpleFOC v2.2.0 on both. The only difference I can see is that the Windows port is COM3, whereas the Linux port is /dev/ttyACM0.
My script is the following and I would appreciate any help or advice to get this working on Linux. Thank you.
#include <SimpleFOC.h>
#define PI 3.1415926535897932384626433832795
// Magnetic sensor instance
MagneticSensorSPI AS5x4x = MagneticSensorSPI(8, 14, 0x3FFF);
void setup() {
// initialize magnetic sensor hardware
AS5x4x.init();
// use monitoring with serial
Serial.begin(9600);
Serial.println("Ready.");
_delay(1000);
}
void loop() {
Serial.println(AS5x4x.getAngle()); // display angle
}