Piko Prasetyo
New member
I am sorry for my bad English because this language is not my mother tongue. I am in the middle of some competition, and to make that competition I use teensy 4.1 as my chosen microcontroller. The program runs really well but sometimes when I put teensy 4.1 into the custom PCB, Teensy will be running only for a while. So I decided to perform a 15-second method of pushing the push button to make teensy go to programming mode. the program can be uploaded but only running for a while again.
I am sorry, I can't give all the program to you because it was for a competition.
I know that I am asking a basic knowledge but sometimes I want to know why I make the teensy die. I have bought 5 teensy and all just die right now.
I am sorry, I can't give all the program to you because it was for a competition.
Code:
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_BME280.h>
#include <Adafruit_Sensor.h>
#include <string.h>
#include <math.h>
#include <TimeLib.h>
#include <EEPROM.h>
#include <Servo.h>
////////////////////////////
#include <TinyGPS++.h>
TinyGPSPlus gps;
const int UTC_offset = 0;
time_t UpdateSebelumnya = 0;
////////////////////////////
//Container
float VOLTAGE, TEMP, Acuan_0, Pressure_Simulasi;
double ALTITUDE;
int PACKET_COUNT = 0, SENSOR_VALUE, i, count_motor;
char PACKET_TYPE = 'C', MODE = 'F', TP_RELEASE = 'N', dataTerima[30], dataTerima2[120], datasimp[7], datartc1[3], datartc2[3], datartc3[3];
char GPS_TIME[10], GPS_LATITUDE[10], GPS_LONGITUDE[10], GPS_ALTITUDE[10];
String TEAM_ID = "1010", MISSION_TIME = "00:00:00.00", dataKirim, dataGCS, CMD_ECHO, SOFTWARE_STATE;
//String GPS_TIME = "00:00:00", GPS_LATITUDE = "12.0999", GPS_LONGITUDE = "120.9999", GPS_ALTITUDE = "120.1";
String DataSimp, DataRTC;
int GPS_SATS = 1, ALTITUDE_NEW, ALTITUDE_OLD, j, tunda = 0, tunda_waktu = 0;
bool Telemetri = false, Pewaktu = false, Pewaktu_TP = false, Simulasi_Ena = false, Simulasi_Act = false, Simulasi_Calc = false, ALTITUDE_BOOL = false, ALTITUDE_TD_BOOL[4];
bool Motor_ON = false;
uint8_t incomingByte = 0, BufferPos, incomingByte2 = 0, BufferPos2;
unsigned long waktu, hundreth1, hundreth2;
unsigned int alamat_EEPROM = 4000;
Adafruit_BME280 bme;
Servo ServoContainer;
const int chipSelect = BUILTIN_SDCARD;
const int buzzer = 34;
const int motor1pin1 = 36;
const int motor1pin2 = 37;
const int camera = 35;
tmElements_t te;
time_t unixTime;
int tahun, bulan, hari, jam, menit, detik;
int CE, LS;
//Komunikasi Kontainer to GCS (Terima)
void Komunikasi_C_GCS_ASK() {
}
//Komunikasi Kontainer to Payload (terima dan kirim)
void Komunikasi_C_TP() {
}
void Komunikasi_C_TP_ASK() {
}
//Data struktur dan integritas akusisi serta pengiriman kontainer data (kirim GCS)
void Data_Akusisi() {
}
void Data_Akusisi_Simulasi() {
}
void Komunikasi_C_GCS_ANSWER() {
Serial5.print(TEAM_ID);
Serial5.print(",");
Format_Print(hour());
Serial5.print(":");
Format_Print(minute());
Serial5.print(":");
Format_Print(second());
Serial5.print(".");
Format_Print(hundreth2);
Serial5.print(",");
Serial5.print(PACKET_COUNT);
Serial5.print(",");
Serial5.print(PACKET_TYPE);
Serial5.print(",");
Serial5.print(MODE);
Serial5.print(",");
Serial5.print(TP_RELEASE);
Serial5.print(",");
Serial5.print(ALTITUDE, 1);
Serial5.print(",");
Serial5.print(TEMP, 1);
Serial5.print(",");
Serial5.print(VOLTAGE, 2);
Serial5.print(",");
Serial5.print(GPS_TIME);
Serial5.print(",");
Serial5.print(GPS_LATITUDE);
Serial5.print(",");
Serial5.print(GPS_LONGITUDE);
Serial5.print(",");
Serial5.print(GPS_ALTITUDE);
Serial5.print(",");
Serial5.print(GPS_SATS);
Serial5.print(",");
Serial5.print(SOFTWARE_STATE);
Serial5.print(",");
Serial5.print(CMD_ECHO);
Serial5.print("\r");
}
void SD_Card_Simpan() {
File dataFile = SD.open("datalog.csv", FILE_WRITE);
if (dataFile) {
dataFile.print(TEAM_ID);
dataFile.print(",");
dataFile.print(MISSION_TIME);
dataFile.print(",");
dataFile.print(PACKET_COUNT);
dataFile.print(",");
dataFile.print(PACKET_TYPE);
dataFile.print(",");
dataFile.print(MODE);
dataFile.print(",");
dataFile.print(TP_RELEASE);
dataFile.print(",");
dataFile.print(ALTITUDE, 1);
dataFile.print(",");
dataFile.print(TEMP, 1);
dataFile.print(",");
dataFile.print(VOLTAGE, 2);
dataFile.print(",");
dataFile.print(GPS_TIME);
dataFile.print(",");
dataFile.print(GPS_LATITUDE);
dataFile.print(",");
dataFile.print(GPS_LONGITUDE);
dataFile.print(",");
dataFile.print(GPS_ALTITUDE);
dataFile.print(",");
dataFile.print(GPS_SATS);
dataFile.print(",");
dataFile.print(SOFTWARE_STATE);
dataFile.print(",");
dataFile.println(CMD_ECHO);
dataFile.close();
}
else {
// Serial.println("error opening datalog.csv");
}
}
void Simpan_EEPROM() {
customVar.PACKET_COUNT = PACKET_COUNT;
if (SOFTWARE_STATE == "LAUNCH_WAIT") {
customVar.SOFTWARE_STATE_Code = 0;
}
if (SOFTWARE_STATE == "ASCENT") {
customVar.SOFTWARE_STATE_Code = 1;
}
if (SOFTWARE_STATE == "DESCENT") {
customVar.SOFTWARE_STATE_Code = 2;
}
if (SOFTWARE_STATE == "SECOND_PARACHUTE") {
customVar.SOFTWARE_STATE_Code = 3;
}
if (SOFTWARE_STATE == "TP_RELEASE") {
customVar.SOFTWARE_STATE_Code = 4;
}
if (SOFTWARE_STATE == "TOUCH_DOWN") {
customVar.SOFTWARE_STATE_Code = 5;
}
EEPROM.put(4000, customVar);
}
void Tugas() {
if (SOFTWARE_STATE == "SECOND_PARACHUTE") {
//Servo gerakan 1
Motor_Servo_Top_Lid();
}
if (SOFTWARE_STATE == "TP_RELEASE") {
//Servo gerakan 2
//Kamera bonus
//Katrol
Motor_Servo_Bottom_Lid();
Camera_ON();
Motor_DC();
}
if (SOFTWARE_STATE == "TOUCH_DOWN") {
Camera_OFF();
Buzzer();
}
}
//Main Inisialisasi
void setup() {
Serial5.begin(19200);
Serial6.begin(9600);
Serial4.begin(19200);
Read_Last_Entry();
ServoContainer.attach(15);
ServoContainer.write(90);
pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
pinMode(camera, OUTPUT);
if (!bme.begin(0x76)) {
// Serial.println("BME FAIL!");
}
if (!SD.begin(chipSelect)) {
// Serial.println("SD CARD FAIL!");
}
}
//Main Loop
void loop() {
Komunikasi_C_GCS_ASK();
Komunikasi_GPS_Timezone_Adjust();
if (Telemetri == true) {
if (millis() - waktu >= 250) {
waktu = millis();
Pewaktu_TP = true;
tunda_waktu++;
if (tunda_waktu == 4) {
Pewaktu = true;
tunda_waktu = 0;
}
}
}
if (Telemetri == true && Pewaktu == true && Simulasi_Calc == false && Simulasi_Ena == false && Simulasi_Act == false) {
Komunikasi_GPS_Timezone_Adjust();
Data_Akusisi();
Komunikasi_C_GCS_ANSWER();
Hundreth_Hitung();
SD_Card_Simpan();
Simpan_EEPROM();
Tugas();
Pewaktu = false;
}
if (Telemetri == true && Simulasi_Calc == true && Simulasi_Ena == true && Simulasi_Act == true) {
Komunikasi_GPS_Timezone_Adjust();
Data_Akusisi_Simulasi();
Komunikasi_C_GCS_ANSWER();
Hundreth_Hitung();
SD_Card_Simpan();
Simpan_EEPROM();
Tugas();
Simulasi_Calc = false;
}
if (Telemetri == true && Pewaktu_TP == true) {
Komunikasi_C_TP_ASK();
Pewaktu_TP = false;
}
}
I know that I am asking a basic knowledge but sometimes I want to know why I make the teensy die. I have bought 5 teensy and all just die right now.