Skip to content

Commit

Permalink
Testing with Assembled Hardware
Browse files Browse the repository at this point in the history
  • Loading branch information
WonITKorea committed Aug 7, 2024
1 parent a4572fb commit 444b408
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 44 deletions.
6 changes: 3 additions & 3 deletions .vscode/arduino.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"sketch": "code\\Testing_Crate\\GPS_uBlox\\GPS_uBlox.ino",
"sketch": "code\\Testing_Crate\\TestCode\\TestCode.ino",
"board": "rp2040:rp2040:rpipico",
"port": "COM7",
"port": "COM4",
"output": "../build",
"intelliSenseGen": "global",
"programmer": "esptool",
"configuration": "flash=2097152_0,freq=133,opt=Optimize,rtti=Disabled,stackprotect=Enabled,exceptions=Disabled,dbgport=Disabled,dbglvl=None,usbstack=picosdk,ipbtstack=ipv4only,uploadmethod=default"
"configuration": "flash=2097152_0,freq=133,opt=Optimize,rtti=Disabled,stackprotect=Disabled,exceptions=Disabled,dbgport=Disabled,dbglvl=None,usbstack=picosdk,ipbtstack=ipv4only,uploadmethod=default"
}
27 changes: 16 additions & 11 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"configurations": [
{
"name": "Arduino",
"compilerPath": "C:\\Users\\wonit\\AppData\\Local\\Arduino15\\packages\\rp2040\\tools\\pqt-gcc\\2.1.0-a-d3d2e6b\\bin\\arm-none-eabi-g++",
"compilerPath": "C:\\Users\\user\\AppData\\Local\\Arduino15\\packages\\rp2040\\tools\\pqt-gcc\\2.2.0-d04e724\\bin\\arm-none-eabi-g++",
"compilerArgs": [
"-I",
"-Werror=return-type",
Expand All @@ -17,18 +17,23 @@
],
"intelliSenseMode": "gcc-x64",
"includePath": [
"C:\\Users\\wonit\\AppData\\Local\\Arduino15\\packages\\rp2040\\hardware\\rp2040\\3.6.0\\include",
"C:\\Users\\wonit\\AppData\\Local\\Arduino15\\packages\\rp2040\\hardware\\rp2040\\3.6.0\\cores\\rp2040",
"C:\\Users\\wonit\\AppData\\Local\\Arduino15\\packages\\rp2040\\hardware\\rp2040\\3.6.0\\variants\\rpipico",
"c:\\users\\wonit\\appdata\\local\\arduino15\\packages\\rp2040\\tools\\pqt-gcc\\2.1.0-a-d3d2e6b\\arm-none-eabi\\include\\c++\\12.3.0",
"c:\\users\\wonit\\appdata\\local\\arduino15\\packages\\rp2040\\tools\\pqt-gcc\\2.1.0-a-d3d2e6b\\arm-none-eabi\\include\\c++\\12.3.0\\arm-none-eabi\\thumb",
"c:\\users\\wonit\\appdata\\local\\arduino15\\packages\\rp2040\\tools\\pqt-gcc\\2.1.0-a-d3d2e6b\\arm-none-eabi\\include\\c++\\12.3.0\\backward",
"c:\\users\\wonit\\appdata\\local\\arduino15\\packages\\rp2040\\tools\\pqt-gcc\\2.1.0-a-d3d2e6b\\lib\\gcc\\arm-none-eabi\\12.3.0\\include",
"c:\\users\\wonit\\appdata\\local\\arduino15\\packages\\rp2040\\tools\\pqt-gcc\\2.1.0-a-d3d2e6b\\lib\\gcc\\arm-none-eabi\\12.3.0\\include-fixed",
"c:\\users\\wonit\\appdata\\local\\arduino15\\packages\\rp2040\\tools\\pqt-gcc\\2.1.0-a-d3d2e6b\\arm-none-eabi\\include"
"C:\\Users\\user\\AppData\\Local\\Arduino15\\packages\\rp2040\\hardware\\rp2040\\3.9.4\\include",
"C:\\Users\\user\\AppData\\Local\\Arduino15\\packages\\rp2040\\hardware\\rp2040\\3.9.4\\cores\\rp2040",
"C:\\Users\\user\\AppData\\Local\\Arduino15\\packages\\rp2040\\hardware\\rp2040\\3.9.4\\variants\\rpipico",
"C:\\Users\\user\\AppData\\Local\\Arduino15\\packages\\rp2040\\hardware\\rp2040\\3.9.4\\libraries\\Wire\\src",
"C:\\Users\\user\\Documents\\Arduino\\libraries\\Rtc_by_Makuna\\src",
"C:\\Users\\user\\Documents\\Arduino\\libraries\\Adafruit_ADS1X15",
"C:\\Users\\user\\Documents\\Arduino\\libraries\\Adafruit_BusIO",
"C:\\Users\\user\\AppData\\Local\\Arduino15\\packages\\rp2040\\hardware\\rp2040\\3.9.4\\libraries\\SPI\\src",
"c:\\users\\user\\appdata\\local\\arduino15\\packages\\rp2040\\tools\\pqt-gcc\\2.2.0-d04e724\\arm-none-eabi\\include\\c++\\12.3.0",
"c:\\users\\user\\appdata\\local\\arduino15\\packages\\rp2040\\tools\\pqt-gcc\\2.2.0-d04e724\\arm-none-eabi\\include\\c++\\12.3.0\\arm-none-eabi\\thumb",
"c:\\users\\user\\appdata\\local\\arduino15\\packages\\rp2040\\tools\\pqt-gcc\\2.2.0-d04e724\\arm-none-eabi\\include\\c++\\12.3.0\\backward",
"c:\\users\\user\\appdata\\local\\arduino15\\packages\\rp2040\\tools\\pqt-gcc\\2.2.0-d04e724\\lib\\gcc\\arm-none-eabi\\12.3.0\\include",
"c:\\users\\user\\appdata\\local\\arduino15\\packages\\rp2040\\tools\\pqt-gcc\\2.2.0-d04e724\\lib\\gcc\\arm-none-eabi\\12.3.0\\include-fixed",
"c:\\users\\user\\appdata\\local\\arduino15\\packages\\rp2040\\tools\\pqt-gcc\\2.2.0-d04e724\\arm-none-eabi\\include"
],
"forcedInclude": [
"C:\\Users\\wonit\\AppData\\Local\\Arduino15\\packages\\rp2040\\hardware\\rp2040\\3.6.0\\cores\\rp2040\\Arduino.h"
"C:\\Users\\user\\AppData\\Local\\Arduino15\\packages\\rp2040\\hardware\\rp2040\\3.9.4\\cores\\rp2040\\Arduino.h"
],
"cStandard": "c11",
"cppStandard": "c++17",
Expand Down
16 changes: 5 additions & 11 deletions code/SKIDAQ_Main/SKIDAQ_Main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include <SoftwareSerial.h>
#include "DFRobot_MCP2515.h"
#include <SPI.h>
#include <TM1637.h>

#include <Wire.h>

// ——————————————————————————————————————————————————————————————————————————————
Expand Down Expand Up @@ -103,7 +103,6 @@ int obled = LED_BUILTIN; // On-Board LED for Basic Error Indication
// Instantiation and pins configurations
// Pin 7 - > DIO
// Pin 6 - > CLK
TM1637 tm(6, 7);

// ——————————————————————————————————————————————————————————————————————————————
// Functions Initalization
Expand All @@ -117,7 +116,7 @@ void ADXL345_displaySensorDetails(void);
void ADXL345_displayDataRate(void);
void ADXL345_displayRange(void);
void MCP2515_Init(void);
void TM1637_Init(void);

void blink(int deltime);

// ——————————————————————————————————————————————————————————————————————————————
Expand Down Expand Up @@ -146,19 +145,20 @@ void setup()
;
}
delay(100);
TM1637_Init();

DHT_TaskInit();
ADS1115_Init();
ADXL345_Init();
MCP2515_Init();
blink(1000);
delay(1000);
Serial.println("——————————————————————————————————————————————————————————————————————————————");
Serial.println("* SKIDAQ " + String(FW_Version) + " *");
Serial.println("* By ChaeWon Lim https://github.com/WonITKorea *");
Serial.println("* Based on Open-Ecu-Sim-OBD2-FW *");
Serial.println("* By Rick Spooner https://github.com/spoonieau *");
Serial.println("——————————————————————————————————————————————————————————————————————————————");
tm.display("OKAY");

delay(3000);
}

Expand Down Expand Up @@ -741,12 +741,6 @@ void MCP2515_Init(void)
Serial.println("CAN Status: OK");
}

void TM1637_Init(void)
{
tm.begin();
tm.setBrightnessPercent(90);
}

void blink(int deltime)
{
digitalWrite(LED_BUILTIN, HIGH);
Expand Down
2 changes: 1 addition & 1 deletion code/Testing_Crate/GPS_uBlox/GPS_uBlox.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
SFE_UBLOX_GPS myGPS;

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX. Pin 10 on Uno goes to TX pin on GPS module.
SoftwareSerial mySerial(3, 2); // RX, TX. Pin 10 on Uno goes to TX pin on GPS module.

long lastTime = 0; // Simple local timer. Limits amount of I2C traffic to Ublox module.

Expand Down
208 changes: 190 additions & 18 deletions code/Testing_Crate/TestCode/TestCode.ino
Original file line number Diff line number Diff line change
@@ -1,33 +1,205 @@
// Wire Master Writer
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Writes data to an I2C/TWI slave device
// Refer to the "Wire Slave Receiver" example for use with this
// CONNECTIONS:
// DS3231 SDA --> SDA
// DS3231 SCL --> SCL
// DS3231 VCC --> 3.3v or 5v
// DS3231 GND --> GND

// Created 29 March 2006
/* for software wire use below
#include <SoftwareWire.h> // must be included here so that Arduino library object file references work
#include <RtcDS3231.h>
// This example code is in the public domain.
SoftwareWire myWire(SDA, SCL);
RtcDS3231<SoftwareWire> Rtc(myWire);
for software wire use above */

#include <Wire.h>
/* for normal hardware wire use below */
#include <Wire.h> // must be included here so that Arduino library object file references work
#include <RtcDS3231.h>
#include <Adafruit_ADS1X15.h>

void setup()
RtcDS3231<TwoWire> Rtc(Wire);
/* for normal hardware wire use above */
Adafruit_ADS1115 ads;

// handy routine to return true if there was an error
// but it will also print out an error message with the given topic
bool wasError(const char *errorTopic = "")
{
Wire.begin(0x55); // join I2C bus (address optional for master)
uint8_t error = Rtc.LastError();
if (error != 0)
{
// we have a communications error
// see https://www.arduino.cc/reference/en/language/functions/communication/wire/endtransmission/
// for what the number means
Serial.print("[");
Serial.print(errorTopic);
Serial.print("] WIRE communications error (");
Serial.print(error);
Serial.print(") : ");

switch (error)
{
case Rtc_Wire_Error_None:
Serial.println("(none?!)");
break;
case Rtc_Wire_Error_TxBufferOverflow:
Serial.println("transmit buffer overflow");
break;
case Rtc_Wire_Error_NoAddressableDevice:
Serial.println("no device responded");
break;
case Rtc_Wire_Error_UnsupportedRequest:
Serial.println("device doesn't support request");
break;
case Rtc_Wire_Error_Unspecific:
Serial.println("unspecified error");
break;
case Rtc_Wire_Error_CommunicationTimeout:
Serial.println("communications timed out");
break;
}
return true;
}
return false;
}

byte y = 0;
void setup()
{
Serial.begin(115200);

Serial.print("compiled: ");
Serial.print(__DATE__);
Serial.println(__TIME__);

//--------RTC SETUP ------------
// if you are using ESP-01 then uncomment the line below to reset the pins to
// the available pins for SDA, SCL
// Wire.begin(0, 2); // due to limited pins, use pin 0 and 2 for SDA, SCL

Rtc.Begin();
#if defined(WIRE_HAS_TIMEOUT)
Wire.setWireTimeout(3000 /* us */, true /* reset_on_timeout */);
#endif

RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
printDateTime(compiled);
Serial.println();

if (!Rtc.IsDateTimeValid())
{
if (!wasError("setup IsDateTimeValid"))
{
// Common Causes:
// 1) first time you ran and the device wasn't running yet
// 2) the battery on the device is low or even missing

Serial.println("RTC lost confidence in the DateTime!");

// following line sets the RTC to the date & time this sketch was compiled
// it will also reset the valid flag internally unless the Rtc device is
// having an issue

Rtc.SetDateTime(compiled);
}
}

if (!Rtc.GetIsRunning())
{
if (!wasError("setup GetIsRunning"))
{
Serial.println("RTC was not actively running, starting now");
Rtc.SetIsRunning(true);
}
}

RtcDateTime now = Rtc.GetDateTime();
if (!wasError("setup GetDateTime"))
{
if (now < compiled)
{
Serial.println("RTC is older than compile time, updating DateTime");
Rtc.SetDateTime(compiled);
}
else if (now > compiled)
{
Serial.println("RTC is newer than compile time, this is expected");
}
else if (now == compiled)
{
Serial.println("RTC is the same as compile time, while not expected all is still fine");
}
}

// never assume the Rtc was last configured by you, so
// just clear them to your needed state
Rtc.Enable32kHzPin(false);
wasError("setup Enable32kHzPin");
Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone);
wasError("setup SetSquareWavePin");
if (!ads.begin(0x49))
{
Serial.println("Failed to initialize ADS.");
while (1)
;
}
// Setup 3V comparator on channel 0
ads.startComparator_SingleEnded(0, 1000);
}

void loop()
{
Wire.beginTransmission(0x55); // transmit to device #8
// sends five bytes
int16_t adc0;

// Comparator will only de-assert after a read
adc0 = ads.getLastConversionResults();
Serial.print("AIN0: ");
Serial.println(adc0);

Wire.write(y);
delay(50); // sends one byte
Wire.endTransmission(); // stop transmitting
delay(100);
if (!Rtc.IsDateTimeValid())
{
if (!wasError("loop IsDateTimeValid"))
{
// Common Causes:
// 1) the battery on the device is low or even missing and the power line was disconnected
Serial.println("RTC lost confidence in the DateTime!");
}
}

RtcDateTime now = Rtc.GetDateTime();
if (!wasError("loop GetDateTime"))
{
printDateTime(now);
Serial.println();
}

RtcTemperature temp = Rtc.GetTemperature();
if (!wasError("loop GetTemperature"))
{
temp.Print(Serial);
// you may also get the temperature as a float and print it
// Serial.print(temp.AsFloatDegC());
Serial.println("C");
}

delay(10000); // ten seconds
}

#define countof(a) (sizeof(a) / sizeof(a[0]))

void printDateTime(const RtcDateTime &dt)
{
char datestring[26];

y++;
delay(500);
snprintf_P(datestring,
countof(datestring),
PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
dt.Month(),
dt.Day(),
dt.Year(),
dt.Hour(),
dt.Minute(),
dt.Second());
Serial.print(datestring);
}

0 comments on commit 444b408

Please sign in to comment.