So I am doing a project with the TF Mini Plus micro-LiDAR running through an Arduino Uno to measure topographic change in dunes. The way I have it set up, it is running in tandem with an RTC and saving to a microSD card with the Gikfun SD Card adapter. I am very very new to coding and even newer to Arduino so I know my code is probably wonky, but I keep getting this error message 'error: expected unqualified-id before '{' token' at line 34/35 before the void_loop section. I am not sure what this is, so any help would be appreciated. Additionally, due to my lack of knowledge with coding any other suggestions or help would be appreciated. The way I tried to code it was to have it take readings from the TF Mini Plus, write those readings to a txt file on the SD Card and include the date/time data from the RTC. Any help is greatly appreciated, the code is below! Thanks.
/*
This program is the interpretation routine of standard output protocol of TFmini-Plus product on
Arduino using a RTC and SD datalogger.
*/
#include <SPI.h>
#include <SD.h>
#include <SoftwareSerial.h> //header file of software serial port
#include <DS3231.h> //DS3231 library
#include <TFMPlus.h> //TF Mini Plus Library
SoftwareSerial Serial1(2, 3); //define software serial port name as Serial1 and define pin2 as RX and pin3 as TX
int dist; //actual distance measurements of LiDAR
int strength; //signal strength of LiDAR
float temprature;
int check; //save check value
int i;
int uart[9]; //save data measured by LiDAR
const int HEADER = 0x59; //frame header of data package
const int chipSelect = 4; //SD card CS pin connected to pin 4 of Arduino
DS3231 rtc(SDA, SCL) // Init the DS3231 using the hardware interface
;
void setup()
{
// Setup Serial connection
Serial.begin(9600); //set bit rate of serial port connecting Arduino with datalogger
Serial1.begin(115200); //set bit rate of serial port connecting TFMini with Arduino
int Initialize_SDcard();
int Initialize_RTC();
}
{
void loop()
if (Serial1.available()) { //check if serial port has data input
if (Serial1.read() == HEADER) { //assess data package frame header 0x59
uart[0] = HEADER;
if (Serial1.read() == HEADER) { //assess data package frame header 0x59
uart[1] = HEADER;
for (i = 2; i < 9; i++) { //save data in array
uart[i] = Serial1.read();
Write_SDcard();
delay(1000); //Wait for 1 seconds before writing the next data
}
{
void Write_SDcard() {
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("LoggerCD.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.print(rtc.getDateStr()); //Store date on SD card
dataFile.print(","); //Move to next column using a ","
dataFile.print(rtc.getTimeStr()); //Store date on SD card
dataFile.print(","); //Move to next column using a ","
dataFile.print(dist); //Store date on SD card
dataFile.print(","); //Move to next column using a ","
dataFile.println(); //End of Row move to next row
dataFile.close(); //Close the file
}
else
Serial.println("OOPS!! SD card writing failed");
}
{
void Initialize_SDcard() {
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
// open the file.
File dataFile = SD.open("LoggerCD.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println("Date,Time,Distance"); //Write the first row of the excel file
dataFile.close();
}
{
void Initialize_RTC() {
// Initialize the rtc object
rtc.begin();
//The following lines can be uncommented to set the date and time for the first time
/*
rtc.setDOW(FRIDAY); // Set Day-of-Week to SUNDAY
rtc.setTime(18, 46, 45); // Set the time to 12:00:00 (24hr format)
rtc.setDate(6, 30, 2017); // Set the date to January 1st, 2014
*/
}
// Confusing section!!!
void Read_TFMini()
{
check = uart[0] + uart[1] + uart[2] + uart[3] + uart[4] + uart[5] + uart[6] + uart[7];
if (uart[8] == (check & 0xff)) { //verify the received data as per protocol
dist = uart[2] + uart[3] * 256; //calculate distance value
strength = uart[4] + uart[5] * 256; //calculate signal strength value
temprature = uart[6] + uart[7] * 256; //calculate chip temprature
temprature = temprature / 8 - 256;
}
{
void Read_DateTime()
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
}
void Read_TFMini()
{
Serial.print("dist = ");
Serial.print(dist); //output measure distance value of LiDAR
// delay(1000);
}