I don't think I'm built for This - made the scale work and didn't made the sd work

March 22 2025 

I am so beyond frustrated. Nothing works. Something works one day and then completely stops working the next. It's driving me insane. 

I got the scale/load cell setup. There was an example where it calibrated the scale so that's very nice. I coded it so that it gives me a message in the serial port if the weight is over a certain amount. It works well. 

The huge issue is that I don't know how to use GitHub and I struggle to get code from GitHub into the arduino software. I don't understand why, but for some reason it doesn't want to talk to my SD card. I don't really understand the language adruino wants me to code in, so I feel like I'm half guessing all the time. 

I can sort everything out if I can just get the SD card to talk to the code. I cannot for the life of me understand why it's not talking. Here's the code I'm using for that:

#include <WiFi.h>
#include <AudioFileSourcePROGMEM.h>
#include <AudioFileSourceSD.h>
#include <AudioGeneratorMP3a.h>
#include <AudioOutputI2S.h>
#include <SPI.h>
#include <SD.h>

// Or play an MP3 file from the microSD card:
#define USE_MICROSD_CARD pdTRUE
#define FILE_PATH "alltheprettylittlehorses.mp3"


#define DAC_BCLK_PIN 15
#define DAC_LRCLK_PIN 16
#define DAC_DATA_PIN 17
#define MICROSD_SPI_SS_PIN 41
#define MICROSD_SPI_SCK_PIN 42
#define MICROSD_SPI_MOSI_PIN 43
#define MICROSD_SPI_MISO_PIN 44
#define RGB_LED_PIN 45


AudioGeneratorMP3a *mp3;
AudioFileSourcePROGMEM *file;
AudioFileSourceSD *sd_file;
AudioOutputI2S *dac;
unsigned long last_led_blink = 0;
int led_color_index = 0;
int colors[][3] = {
{255, 0, 0}, // Red
{0, 255, 0}, // Green
{0, 0, 255}, // Blue
{255, 255, 0}, // Yellow
{255, 0, 255} // Magenta
};

void setup() {
// "USB CDC On Boot" must be enabled
Serial.begin(9600);
WiFi.mode(WIFI_OFF);

pinMode(RGB_LED_PIN, OUTPUT);

if (USE_MICROSD_CARD) {
// Set up access to microSD card
SPI.begin(MICROSD_SPI_SCK_PIN, MICROSD_SPI_MISO_PIN, MICROSD_SPI_MOSI_PIN, MICROSD_SPI_SS_PIN);
if (!SD.begin(MICROSD_SPI_SS_PIN)) {
while (1) {
Serial.println("Card mount failed");
delay(1000);
}
}
}

dac = new AudioOutputI2S();
dac->SetPinout(DAC_BCLK_PIN, DAC_LRCLK_PIN, DAC_DATA_PIN);

// Output can be very loud, so we're setting the gain less than 1
dac->SetGain(3);
mp3 = new AudioGeneratorMP3a();
playMP3();
Serial.println("Ready");
}

void playMP3() {
if (USE_MICROSD_CARD) {
sd_file = new AudioFileSourceSD(FILE_PATH);
mp3->begin(sd_file, dac);
}
Serial.println("Playing MP3...");
}

void loop() {
if (mp3->isRunning()) {
if (!mp3->loop()) {
mp3->stop();
Serial.println("Done");
// Play the file again
playMP3();
}
}

}


l triple checked the file name, I know the file is on the card, I switched out the speakers, I cried, I took suggestions from the errors on changing things with the language, I tried defining it differently, I tried adding serial print markers to see where it was broken, I tried just testing it with an .h file, I tried getting it from GitHub different ways, and none of those things made it play the sound. 

The scale program with the if/then statement to the serial port is working, so if we figure out the SD card I should be able to add that and have it working. I think that's what makes me mot frustrated- in theory it shouldn't be difficult. But for some reason I can't get it to work at all and often I never understand exactly why.   

In cultural exchange there is a part in the process right before you assimilate where you really hate the new culture  and all its differences. I think I'm in that stage for electronic art. The highs are so high, but the lows are so low. And everything is difficult. And I can't just throw fire at it and make something happen. But I will endure. Because I do want my crane to fly. 

Code for the scale:
#include "HX711.h"

HX711 scale;

// adjust pins if needed
// uint8_t dataPin = 6;
// uint8_t clockPin = 7;
uint8_t dataPin = 6; // for ESP32
uint8_t clockPin = 7; // for ESP32

void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HX711_LIB_VERSION: ");
Serial.println(HX711_LIB_VERSION);
Serial.println();

scale.begin(dataPin, clockPin);

Serial.print("UNITS: ");
Serial.println(scale.get_units(10));

Serial.println("\nEmpty the scale, press a key to continue");
while(!Serial.available());
while(Serial.available()) Serial.read();

scale.tare();
Serial.print("UNITS: ");
Serial.println(scale.get_units(10));


Serial.println("\nPut 1000 gram in the scale, press a key to continue");
while(!Serial.available());
while(Serial.available()) Serial.read();

scale.calibrate_scale(1000, 5);
Serial.print("UNITS: ");
Serial.println(scale.get_units(10));

Serial.println("\nScale is calibrated, press a key to continue");
// Serial.println(scale.get_scale());
// Serial.println(scale.get_offset());
while(!Serial.available());
while(Serial.available()) Serial.read();
}


void loop()
{
Serial.print("UNITS: ");
Serial.println(scale.get_units(10));
delay(250);
if (scale.get_units(10) > 700) {
Serial.println ("baby!");
}
delay(500);
}




Comments

Popular posts from this blog

locking in with the electronics

A Week Without Rob: Fabricating Work and Getting Supplies

I always forget to do these: Fabrication is Completed