Hello. Here is a breakdown of my current components:
- Arduino Mega 2560
- USB Host Shield (here is a link to the one I bought - https://www.amazon.com/ARCELI-Shield-Arduino-Support-Android/dp/B07J2KKGZ4/ref=d_pd_di_sccai_cn_sccl_2_1/131-7693533-7483233?pd_rd_w=oiH1k&content-id=amzn1.sym.e13de93e-5518-4644-8e6b-4ee5f2e0b062&pf_rd_p=e13de93e-5518-4644-8e6b-4ee5f2e0b062&pf_rd_r=F43PQ8ANH1947DYB0DZ5&pd_rd_wg=S0wCX&pd_rd_r=7658f02a-a8a2-4dd4-8b32-5d73e82816ec&pd_rd_i=B07J2KKGZ4&psc=1)
- A normal FAT32 USB thumb drive (multiple different ones)
I cannot for the life of me figure out how to write code wherein the arduino is able to interface with the thumb drive and write it anything. I am not the best with writing code; I have been troubleshooting this issue with CHATGPT for days now, trying alternative methods and libraries.
I can go back through my literal hundreds of different versions of code and paste some examples, but I would rather hear if any of you have a better method for getting this task done.
I am currently using the newest arduino IDE version 2.1.1. It seems like no library wants to work with this version. I have redownloaded them all using different methods (such as Greiman's UsbFat and Felis' USB_Host_Shield_2.0.)
At the end of the day, my end goal is to make a simple data logger. I have an ADC and RTC connected to my arduino providing the date, time, and voltage. I want those three inputs to be sent to my USB thumb drive every minute or so. I can provide that code if you want:
#include <Wire.h>
#include <Adafruit_ADS1X15.h>
#include <RTClib.h>
// Constants
const int ADS1115_ADDRESS = 0x48; // I2C address of the ADS1115 ADC
const int RTC_ADDRESS = 0x68; // I2C address of the DS3231 RTC
Adafruit_ADS1115 ads; // Remove the parameter from the constructor
RTC_DS3231 rtc; // Use RTC_DS3231 from the RTClib library
void setup()
{
Serial.begin(9600);
Wire.begin();
// Initialize the ADS1115 ADC
ads.begin(ADS1115_ADDRESS); // Initialize with the desired I2C address
// Initialize the DS3231 RTC
rtc.begin();
// Adjust the time on the RTC
//DateTime adjustedTime(2023, 7, 6, 8, 22, 00); // Set the desired date and time
//rtc.adjust(adjustedTime); // Adjust the RTC time
}
void loop()
{
// Read the current time from the DS3231 RTC
DateTime now = rtc.now();
// Convert hour, minute and second values to strings with leading zeros
String hourString = now.hour() < 10 ? "0" + String(now.hour()) : String(now.hour());
String minuteString = now.minute() < 10 ? "0" + String(now.minute()) : String(now.minute());
String secondString = now.second() < 10 ? "0" + String(now.second()) : String(now.second());
// Read the voltage from the ADS1115 ADC
int16_t adcValue = ads.readADC_SingleEnded(0); // Read from channel 0
float voltage = adcValue * 0.0001875; // Convert raw value to voltage (6.144V / (2^15bits))
// Convert Voltage to Temperature
float temperature = voltage * (1800 / 5);
// Print the Current Time
Serial.print("Current Time: ");
Serial.print(hourString);
Serial.print(":");
Serial.print(minuteString);
Serial.print(":");
Serial.print(secondString);
Serial.println();
// Print the Voltage
Serial.print("Voltage: ");
Serial.print(voltage, 3);
Serial.println(" V");
// Print the Converted Temperature
Serial.print("Temperature: ");
Serial.print(temperature, 0);
Serial.println(" °C");
// Leave a Space between datapoints
Serial.println("");
delay(1000); // Wait for 1 second before reading again
}
By the way, I am open to hearing other ways of saving/writing the data. If you think I should go with an SD Card, for example, I would love to know why/how. I only initially went with the USB thumb drive because I figured it would provide users the best method for taking the data to their computers and downloading the data. I looked into doing it with an SD card, but I could not find anything better. Again, if you think I should switch to a different arduino board, I would love to know why, but I figured the Mega 2560 would be best because it allowed me to connect both the RTC and ADC.
Like I mentioned, I am in no way experienced writing lots of code. Learning about libraries and such was an experience for me. I have learned a lot over this past week or two, however, at this point, I really just want this project finished.