STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1
// #include <WiFi.h>
2
// #include <ETH.h>
3
// #include <SPI.h>
4
// #include <EthernetUdp.h>
5
// #include <Ethernet.h>
6
// #include <ADS126X.h>
7
// #include <esp_system.h>
8
9
// #define ETH_CLK_PIN 7
10
// #define ETH_MISO_PIN 41
11
// #define ETH_MOSI_PIN 13
12
// #define ETH_CS_PIN 6
13
// #define ETH_PHY_ADDR 0
14
15
// IPAddress staticIP(192, 168, 2, 100);
16
// IPAddress gateway(192, 168, 2, 1);
17
// IPAddress subnet(255, 255, 255, 0);
18
// IPAddress dns(192, 168, 2, 1);
19
// IPAddress receiverIP(192, 168, 2, 1);
20
// const int receiverPort = 5006;
21
// EthernetUDP udp;
22
// void EthernetInit() {
23
// // Generate MAC
24
// uint64_t chipid = ESP.getEfuseMac();
25
// byte mac[6];
26
// mac[0] = 0x02;
27
// mac[1] = 0x00;
28
// mac[2] = (chipid >> 32) & 0xFF;
29
// mac[3] = (chipid >> 24) & 0xFF;
30
// mac[4] = (chipid >> 16) & 0xFF;
31
// mac[5] = (chipid >> 8) & 0xFF;
32
33
// // SPI + Ethernet
34
// SPI.begin(ETH_CLK_PIN, ETH_MISO_PIN, ETH_MOSI_PIN, ETH_CS_PIN);
35
// Ethernet.init(ETH_CS_PIN);
36
// Ethernet.begin(mac, staticIP, dns, gateway, subnet);
37
38
// udp.begin(5005);
39
// }
40
41
// ADS126X adc;
42
// #define DRDY_PIN 7
43
// #define DOUT 41
44
// #define DIN 5
45
// #define SCLK 13
46
// #define CS 40
47
// int pos_pin = 0; // Positive input (AIN0)
48
// int neg_pin = 0xA; // Negative input (AINCOM)
49
50
// #define BUFFER_SIZE 1000
51
// String buffer[BUFFER_SIZE];
52
// int bufferIndex = 0;
53
54
// adc.setReference(ADS126X_REF_NEG_VSS, ADS126X_REF_POS_VDD);
55
// uint8_t power = adc.readRegister(ADS126X_POWER);
56
// power &= ~(1 << 2);
57
// adc.writeRegister(ADS126X_POWER);
58
59
// unsigned long start_time = 0;
60
// unsigned long readTime = 0;
61
// int readCount = 0;
62
63
// void setup() {
64
// Serial.begin(115200);
65
// Serial.println("Ethernet + ADC UDP Sender");
66
67
// // --- SPI + ADC Setup ---
68
// adc.begin(CS);
69
// adc.startADC1();
70
// adc.setRate(ADS126X_RATE_38400);
71
// pinMode(DRDY_PIN, INPUT);
72
73
// // --- Ethernet Setup ---
74
// SPI.begin(ETH_CLK_PIN, ETH_MISO_PIN, ETH_MOSI_PIN, ETH_CS_PIN);
75
// delay(1000);
76
// EthernetInit();
77
// delay(1000);
78
79
// Serial.print("ESP32 IP: ");
80
// Serial.println(Ethernet.localIP());
81
82
// udp.begin(5005); // local UDP port
83
// }
84
85
// void loop() {
86
// // Wait for ADC ready
87
88
// while (digitalRead(DRDY_PIN) == HIGH) {
89
// // wait
90
// }
91
// start_time = micros();
92
// long rawValue = adc.readADC1(pos_pin, neg_pin); // raw ADC
93
// while (digitalRead(DRDY_PIN) == HIGH) {
94
// // wait
95
// }
96
// rawValue = adc.readADC1(pos_pin, neg_pin); // raw ADC
97
// float voltage = (float)(rawValue) * 5.0 / 8388608.0; // Convert to voltage
98
// readTime = micros() - start_time;
99
100
// readCount++;
101
102
// String sample = String(rawValue) + "," + String(voltage, 6) + "," +
103
// String(millis()) + "," + String(readTime);
104
105
// buffer[bufferIndex++] = sample;
106
107
// //UPDATES BUFFER
108
109
// if (bufferIndex >= BUFFER_SIZE) {
110
111
// Serial.println("Buffer full, sending UDP packet...");
112
113
// // Concatenate buffer into one big string
114
// String packetData;
115
// for (int i = 0; i < BUFFER_SIZE; i++) {
116
// packetData += buffer[i] + "\n";
117
// }
118
119
// // Send over UDP
120
// udp.beginPacket(receiverIP, receiverPort);
121
// udp.write(packetData.c_str());
122
// udp.endPacket();
123
124
// Serial.println("UDP packet sent!");
125
126
// // Clear buffer
127
// bufferIndex = 0;
128
// }
129
130
// delay(5); // adjust data rate
131
// }
firmware
PT_Board
Old_PT_2
src
main.cpp
Generated by
1.15.0