Go Down

Topic: Arduino Nano Overload? (Read 212 times) previous topic - next topic

nolansneeder

I'm not sure if this is the right place to post this but I am using a gps unit (SparkFun U-Blox SAM-M8Q) and am going to be using a pair of Xbees eventually.

I have 5 sensors hooked up to my Arduino nano:
- 1 barometer
- 2 accelerometers
- 1 gyroscope
- 1 GPS receiver

I'm currently just trying to read all of the sensors and print the data to the serial monitor in a csv format. Eventually this data will be saved on an SD card and/or sent wirelessly to my laptop. Currently when I'm trying to read the data over the serial monitor it reads slower than it should and also spits out a lot of gibberish with the data. I've added a timer to only read once every 1 or 2 seconds or whatever but it's still reading slower than the timer says it should. Is this possibly just overloading the processor?

Here's what my code looks like to write to the serial port:

   // Current Time
   Serial.print(millis() + ", ");
 
   // Barometer
   Serial.print(String(barometer.readFloatPressure()) + ", ");
   Serial.print(String(barometer.readTempF()) + ", ");
   Serial.print(String(barometer.readFloatAltitudeFeet()) + ", ");
 
   // 3g Accelerometer
   Serial.print(String(analogRead(littleX)) + ", ");
   Serial.print(String(analogRead(littleY)) + ", ");
   Serial.print(String(analogRead(littleZ)) + ", ");
 
   // 200g Accelerometer
   Serial.print(String(analogRead(bigX)) + ", ");
   Serial.print(String(analogRead(bigY)) + ", ");
   Serial.print(String(analogRead(bigZ)) + ", ");
 
   // Gyroscope
   Serial.print(String(event.gyro.x) + ", ");
   Serial.print(String(event.gyro.y) + ", ");
   Serial.print(String(event.gyro.z) + ", ");
 
   // GPS
   Serial.print(String(latitude) + ", ");
   Serial.print(String(longitude) + ", ");
   Serial.println(String(altitude));

And here is just a snippet from what the serial monitor looks like:

  4082908.47, 69.66, 5445.71, 364, 369, 448, 365, 366, 365, -0.02, -0.03, 0.00, 396976912,    -1048882867, 1671586
  ⸮⸮⸮⸮۾⸮w}I⸮w⸮⸮⸮⸮⸮⸮/⸮5w⸮⸮⸮⸮⸮⸮⸮]⸮⸮⸮y⸮⸮⸮⸮⸮⸮l⸮⸮⸮}⸮zl⸮?l'⸮R⸮y⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮8⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮\⸮⸮&⸮⸮׺⸮Z⸮~⸮>⸮w⸮⸮⸮C⸮⸮⸮⸮⸮5⸮⸮⸮l>⸮⸮⸮⸮⸮o⸮⸮鱦⸮?ǵ⸮{9⸮X⸮⸮⸮{⸮⸮⸮y⸮ѻ⸮⸮w⸮⸮⸮}e⸮⸮Xv⸮⸮⸮R⸮{⸮y⸮⸮⸮⸮⸮⸮{⸮⸮⸮⸮.3⸮⸮⸮0⸮⸮  7⸮:3⸮⸮_߮⸮⸮⸮⸮V
  ~⸮~82915.83, 69.66, 5443.99, 363, 369, 449, 366, 368, 367, -0.01, -0.03, -0.00, 396976950, -1048882816, 1672675
   82915.83, 69.66, 5443.77, 364, 368, 449, 366, 367, 365, -0.02, -0.03, 0.00, 396976914, -1048882823, 1672493

I've also tried maxing out the baud rate just to see if that was the problem but I don't think so. Any info/input would be very helpful! Thank you.

ieee488

Using String are bad.
Use char arrays.

In addition, maximum baud rate of 38400 on Software serial.

srnet

#2
Mar 23, 2019, 06:11 pm Last Edit: Mar 23, 2019, 06:15 pm by srnet
Quote
Here's what my code looks like to write to the serial port:
So we cannot see the important bits, i.e. the code that could be causing the problems.  


Quote
I have 5 sensors hooked up to my Arduino nano:
- 1 barometer
- 2 accelerometers
- 1 gyroscope
- 1 GPS receiver
Given that setup, and that you also want to add an SD card and your using Strings (eek! run for the hills) , I would imagine the chances of the program fitting in a Nano and\or being stable are fairly close to zero.
http://www.50dollarsat.info/
http://www.loratracker.uk/

nolansneeder

Ok. I'll try and use char arrays instead of strings. I'm still guessing I might have to beef up my processor. I'll put the rest of my code below. The setup function is all I didn't show. It says it's only taking around 60% of the available memory but I don't think that has anything to do with the issue I'm experiencing.

  Serial.begin(2000000);

  while(!Serial) // Waits for user to open the terminal

  Wire.begin();

  // Barometer
  if (barometer.beginI2C() == false) //Begin communication over I2C
  {
    Serial.println(F("The barometer did not respond. Please check wiring."));
    while(1); //Freeze
  }

  // Gyro
  gyro.enableAutoRange(true);
 
  if (!gyro.begin())
  {
    Serial.println(F("The gyro did not respond. Please check wiring."));
    while(1); //Freeze
  }

  // GPS
  if(GPS.begin() == false) // Bad wiring (I think)
  {
    Serial.println((F("Ublox GPS not detected at default I2C address. Please check wiring.")));
    while(1);

    GPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
    GPS.saveConfiguration(); //Save the current settings to flash and BBR
  }

  // Headings for CSV file
  Serial.println(F("Time (ms), Air Pressure (Pa), Temperature (Deg F),"
    "Barometer Altitude (ft), ADXL 335 X, ADXL 335 Y, ADXL 335 Z,"
    "ADXL 377 X, ADXL 377 Y, ADXL 377 Z, Angular Velocity X (rad/s),"
    "Angular Velocity Y (rad/s), Angular Velocity Z (rad/s),"
    "Latitude (Deg*10^-7), Longitude (Deg*10^-7), GPS Altitude (mm)"));

I might try decreasing my baud rate. My serial monitor said that 2000000 was possible but ieee488 that the max is 38400 so I might try that next.

nolansneeder

Never mind. Most of my issue is because I wasn't converting my millis() call to a string lol.

Go Up