-
Notifications
You must be signed in to change notification settings - Fork 8
/
1.Send_data_via_wifi.ino
105 lines (93 loc) · 2.19 KB
/
1.Send_data_via_wifi.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <WiFi.h>
#include <WiFiUdp.h>
#include <SPI.h>
//ADC
//#define button_pin 7
const int button_pin = 7;
const int chip_select = 10; // Assuming SPI chip select pin
int test_DRDY = 5;
int button_state = 0;
const int size_of_data = 1350; //864;
byte output[size_of_data] = {};
//WiFi
char ssid[] = "Wifi Name";
char pass[] = "password";
WiFiUDP udp;
void sendCommand(byte command)
{
SPI.transfer(command);
}
void writeByte(byte registers, byte data)
{
char spi_data = 0x40 | registers;
char spi_data_array[3];
spi_data_array[0] = spi_data;
spi_data_array[1] = 0x00;
spi_data_array[2] = data;
SPI.transfer(spi_data_array, 3);
}
void setup()
{
//ADC
pinMode(button_pin, INPUT); //initialize the led pin as output
pinMode(chip_select, OUTPUT);
digitalWrite(chip_select, LOW);
SPI.begin();
SPI.beginTransaction(SPISettings(600000, MSBFIRST, SPI_MODE1));
sendCommand(0x02); // wakeup
sendCommand(0x0A); // stop
sendCommand(0x06); // reset
sendCommand(0x11); // sdatac
// Write configurations
writeByte(0x01, 0x96);
writeByte(0x02, 0xD4);
writeByte(0x03, 0xFF);
writeByte(0x04, 0x00);
writeByte(0x0D, 0x00);
writeByte(0x0E, 0x00);
writeByte(0x0F, 0x00);
writeByte(0x10, 0x00);
writeByte(0x11, 0x00);
writeByte(0x15, 0x20);
writeByte(0x17, 0x00);
writeByte(0x05, 0x00);
writeByte(0x06, 0x00);
writeByte(0x07, 0x00);
writeByte(0x08, 0x00);
writeByte(0x09, 0x00);
writeByte(0x0A, 0x00);
writeByte(0x0B, 0x00);
writeByte(0x0C, 0x00);
writeByte(0x14, 0x80);
sendCommand(0x10);
sendCommand(0x08);
//wifi
WiFi.begin(ssid, pass);
udp.begin(13900);
}
int a = 30;
int sc;
void loop()
{
button_state = digitalRead(button_pin);
if (button_state == HIGH)
{
test_DRDY = 10;
}
if (test_DRDY == 10 && button_state == LOW)
{
test_DRDY = 0;
for (int i = 0; i < 27; i++)
{
output[sc] = SPI.transfer(0xFF); // 0xFF is a dummy byte to trigger the read
sc = sc + 1;
}
if (sc == size_of_data)
{
udp.beginPacket("192.168.1.241", 13900);
udp.write(output, sc);
udp.endPacket();
sc = 0 ;
}
}
}