Xiao "Freezes" when Trying to Upload Sketch with "MMA7455.h" Library

Hello,

I just got a pack of 3 Seeduino Xiaos and soldered the pins on and ran the blink program successfully (I am using the Arduino IDE). I am trying to upload a sketch that uses Adafruit’s Neopixel library and a library for the MMA7455 accelerometer paired with the Wire library. I can upload a plain Neopixel library example, but when I try to upload a sketch with the MMA7455 library, it uploads “successfully,” but my Xiao stops connecting to my computer and I can no longer select the port and the code doesn’t run. I am able to upload code if I short the reset pad twice.

I mention the libraries because I think that is what’s causing the problem, but I’ll post the “MMA_7455_Demo” example code for the MMA7455 library. This is the code that freezes the Xiao. (I didn’t see an option for specific code tags so please let me know if I pasted that code wrong). Thanks!

MMA_7455 library download link

#include <Wire.h> //Include the Wire library
#include <MMA_7455.h> //Include the MMA_7455 library

MMA_7455 accel = MMA_7455(); // Make MMA7455 object

char xVal, yVal, zVal; // Return value variables

void setup() {
Serial.begin(9600); // Use the Serial Monitor window at 9600 baud

// Set the g force sensitivity: 2=2g, 4=4g, 8-8g
accel.initSensitivity(2);

// Provide oiffset values so that sensor displays 0, 0, 63
// (or close to it) when positioned on a flat surface, all pins
// facing down

// Update the numbers with your own values from the MMA7455_CalibrateOffset sketch.
accel.calibrateOffset(0, 0, 0);
}

void loop() {

// Get the X, Y, anx Z axis values from the device
xVal = accel.readAxis(‘x’); // Read X Axis
yVal = accel.readAxis(‘y’); // Read Y Axis
zVal = accel.readAxis(‘z’); // Read Z Axis

// Display them in the Serial Monitor window.
Serial.print("X: = “);
Serial.print(xVal, DEC);
Serial.print(” Y: = “);
Serial.print(yVal, DEC);
Serial.print(” Z: = ");
Serial.println(zVal, DEC);
delay(1000);
}

Hi nick13579,

I don’t have the sensor MMA7455, so I’m not sure if the following is the correct way, but at least it doesn’t cause a port disappear.

  1. ******** MMA_7455.cpp ********
    MMA_7455::MMA_7455()
    {
    // Wire.begin(); <---- comment out
    }

  2. ******** MMA7455_Demo.ino ********
    void setup() {
    Serial.begin(9600);
    Wire.begin(4, 5); <----- add

1 Like

Hello msfujino,

Thank you so much for your reply! Your suggestion did help the “no port” problem, however, my Xiao was not sending anything to the Serial monitor so I couldn’t debug it. I don’t think the code was running/functioning.

I fully fixed the problem by doing this (Note this is all on top of msfujino’s fix):

In the MMA_7455.h file:
Replace this:
#include “Arduino.h”

With this:
#if defined(ARDUINO) && ARDUINO >= 100
#include “Arduino.h”
#else
#include “WProgram.h”
#endif
#include “Wire.h”

And I kept the line below it to include the Wire class.

THEN
in the Arduino sketch (MMA_7455_Demo.ino) I removed “#include <Wire.h>”

And instead of using your line, “Wire.begin(4, 5);”
I had to replace it with, “Wire.begin();”

If this doesn’t work
If you’re having the same problem and these steps aren’t working, you might want to try and install the Seeeduino USB Serial driver from this link. This is from what I believe is the official Seeed Studios GitHub. Extract the folder and find the .inf file. Right click it and select install. That should solve your problem. It wasn’t letting me install it at first so I had to go to my computer bios and enable the installation of unsigned drivers. Lookup how to do that if it’s not working and then you should be able to install it.

Thank you again msfujino for your help

1 Like