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