SAMD21 supply problem

Hello all,
I am having some strange beaviour from this micro connected to an expansion board.
If I run a script connected to a PC it runs without a problem, but if I connect it do a powerbank or an USB charger it does run the sameway…
Besides this one expansion board just stops working after about a couple of hours running.
Did someone experienced this before?
Thanks

we,come! I have not experienced this before… sounds like the battery is running low… can you give any more information about the setup?

Hello,
I am not using a battery at all, as the ideia is to use a power outlet with USB and a cable connect on the USB-C XIAO.
But I need the RTC, Display and uSD from the expansion board as this is a datalogger.
Was reading about standalone firmware but did not found anydetails how to configure.
Thanks

Can you re-state what the problem is… also I use LiPo to power my XIAO Expansion Board

Hello Christopher,
Thanks for your reply.
I have this code to datalog an RFID system.

#include <Arduino.h>
#include <U8x8lib.h>
#include <PCF8563.h>
PCF8563 pcf;
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SoftwareSerial.h>

const int ledPin =  13;      // the number of the LED pin

U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);   // OLEDs without Reset of the Display

static const int RXPin = D7, TXPin = D6;
static const uint32_t RFIDBaud = 9600;
SoftwareSerial ss(RXPin, TXPin);

File myFile;
String Nome = "Nome";
int amostragem = 5;

byte flag = 0;
int repeat = 5;
String inputRFID = "123456789012345830ksiw91kasdfghjklpoiuytrewwq";

void setup() {
  pinMode(ledPin, OUTPUT);
  ss.begin(RFIDBaud);

  u8x8.begin();
  u8x8.setFlipMode(0);
  u8x8.setFont(u8x8_font_chroma48medium8_r);   // choose a suitable font
  Wire.begin();
  pcf.init();//initialize the clock
  pcf.startClock();//start the clock

  u8x8.setCursor(0, 1);
  u8x8.print("Test SS");
  while (!ss && millis() < 10000) {
    // Wait for serial connection
    delay(50); // Short delay to reduce CPU load
  }

  u8x8.setCursor(0, 2);
  u8x8.print("Set Mode");
  ss.flush();
  ss.print("SD2\r");
  if (ss.available() > 0) {
    String input = ss.readStringUntil('\r');
    u8x8.setCursor(10, 2);
    u8x8.print(input);    
  }
  delay(5000);

  u8x8.setCursor(0, 3);
  u8x8.print("Command RAT");
  ss.flush();
  ss.print("RAT\r");
  delay(100);
  if (ss.available() > 0) {
    String input = ss.readStringUntil('\r');
    u8x8.setCursor(0, 4);
    u8x8.print(input);
  }

  u8x8.setCursor(0, 5);
  u8x8.print("Command MOF");
  ss.flush();
  ss.print("MOF\r");
  delay(3000);
  if (ss.available() > 0) {
    String input = ss.readStringUntil('\r');
    u8x8.setCursor(0, 6);
    u8x8.print(input);
  }

  u8x8.setCursor(0, 7);
  u8x8.print("Test SD");

  pinMode(D2, OUTPUT);          // Modify the pins here to fit the CS pins of the SD card you are using.
  if (!SD.begin(D2)) {
    return;
  }
  u8x8.setCursor(10, 7);
  u8x8.print("OK");

  myFile = SD.open("/conf.txt", FILE_READ);
  if (myFile) {

    Nome = myFile.readStringUntil('\r');
    myFile.read();  //to clean \n
    amostragem = parseNumber(myFile);

    myFile.close();

  delay(5000);
  u8x8.clear();
}

void loop() {
  Time nowTime = pcf.getTime();//get current time
  
  u8x8.setCursor(0, 0);
  u8x8.print("     RFID");

  char day[3];
  char month[3];
  sprintf(day, "%02d", nowTime.day);      // Format day with leading zero
  sprintf(month, "%02d", nowTime.month);  // Format month with leading zero

  u8x8.setCursor(0, 2);
  u8x8.print(day);
  u8x8.print("/");
  u8x8.print(month);
  u8x8.print("/");
  u8x8.print("20");
  u8x8.print(nowTime.year);

  char hour[3];
  char minute[3];
  char second[3];
  sprintf(hour, "%02d", nowTime.hour);      // Format hour with leading zero
  sprintf(minute, "%02d", nowTime.minute);  // Format minute with leading zero
  sprintf(second, "%02d", nowTime.second);  // Format second with leading zero

  u8x8.setCursor(0, 3);
  u8x8.print(hour);
  u8x8.print(":");
  u8x8.print(minute);
  u8x8.print(":");
  u8x8.println(second);

  u8x8.setCursor(0, 5);
  u8x8.print("Name:");
  u8x8.print(Nome);

  u8x8.setCursor(0, 7);
  u8x8.print("Sample:");
  u8x8.print(amostragem);
  u8x8.print(" min");

  if ((nowTime.minute % amostragem == 0) && (nowTime.second == 0) && (flag == 0)){
    flag = 1;
    digitalWrite(ledPin, LOW);
    RFID();
    String Filename = Nome + ".csv";
    myFile = SD.open(Filename, FILE_WRITE);
    if(myFile){
      char dados[100];
      snprintf(dados, sizeof(dados), "20%d,%s,%s,%s,%s,%s", nowTime.year,month,day,hour,minute,inputRFID.c_str());
      myFile.println(dados);
      myFile.close();
  }
  if (nowTime.second != 0){
    flag = 0;
  }

  delay(200);
  digitalWrite(ledPin, HIGH);
}

long parseNumber(File &file) {
  long result = 0;
  int sign = 1;

  char c = file.read();
  while (c == ' ') {
    c = file.read();
  }

  if (c == '-') {
    sign = -1;
    c = file.read();
  } else if (c == '+') {
    c = file.read();
  }

  while (isdigit(c)) {
    result = result * 10 + (c - '0');
    c = file.read();
  }

  return sign * result;
}

void RFID(){
  repeat = 5;
  while (repeat != 0) {
    inputRFID = "";
    ss.flush();
    ss.print("RAT\r");
    delay(100);
    if (ss.available() > 0) {
      inputRFID = ss.readStringUntil('\r');
    }
    inputRFID.replace("_", "");
      repeat = 0;
    }
    else {
        repeat = repeat -1;
    }
}

When it is powered from the PC the readings are ok, but this is supposed to work as stand alone and then it does not work properly when powered from a USB charger (30w) to the USB-C on XIAO…
This never happen to me before with another uC.
Any advice?
Thanks

Try to use a different power source (another charger or powerbank). Powerbanks and USB chargers often limit the amount of current they can supply. While PCs can provide higher and more stable current, some powerbanks and chargers may not supply enough power,

Hello liaifat85,
Have tryed 2 powerbanks and 2 USB chargers, but next step will be measuring all correctly to make shore it is enough.
Thanks.

WOW that is odd… when you say it does nto work… which parts? does the oled work or the sensor work or nothing works?

Just the software serial is not working properlly.
So I have changed the supply and not it is working properly.
Thanks for the help.

1 Like

click solved please and thank you!