3 Connect Arduino ProMini 3.3V 8Mhz Atmega328 to Raspberry Pi
22 #include <DallasTemperature.h>
24 RCSwitch mySwitch = RCSwitch();
28 DallasTemperature sensors(&oneWire);
31 // 513Mhz light sockets
35 int int_0 = 300; // ms
36 int int_1 = 900; // ms
37 int wait = 2000; // ms
38 int repeat = 5; // times
40 void send_513(char *code) {
41 Serial.print("send 513Mhz ");
44 // we have to send same signal at least two times
45 for(int r = 0; r < repeat; r++ ) {
47 digitalWrite(LED_PIN, HIGH);
49 for(int i = 0; i < strlen(code); i++) {
52 if (code[i] == '1' ) {
56 digitalWrite(TX_PIN, HIGH);
57 delayMicroseconds(i1);
58 digitalWrite(TX_PIN, LOW);
59 delayMicroseconds(i2);
62 delayMicroseconds(wait); // guess
65 digitalWrite(LED_PIN, LOW);
71 mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
72 mySwitch.enableTransmit(10); // with sender wired in receiving doesn't work, pin #10
77 Serial.print("press buttons on remote or send AB where A = socket (0..9), B = state (0 = off, 1 = on)\nB00...00 (24 digits) to send binary\n");
81 char serial_data[2]; // socket (0-9), state (0-1)
85 if (mySwitch.available()) {
86 Serial.print(mySwitch.getReceivedBitlength());
87 Serial.print(" bits ");
88 Serial.println(mySwitch.getReceivedValue(), BIN);
89 mySwitch.resetAvailable();
91 if (Serial.available() > 0) {
92 char input = Serial.read();
94 Serial.print("DS18B20 temperature = ");
95 sensors.requestTemperatures();
96 Serial.println( sensors.getTempCByIndex(0) );
100 Serial.readBytesUntil('\n', binary_data, sizeof(binary_data));
101 Serial.print("send B");
102 Serial.println( binary_data );
103 mySwitch.send( binary_data );
106 // light sockets at 513 Mhz
108 send_513("1000100110110000000000010");
111 send_513("1011001001011111000000010");
114 if ( input >= 0x30 && input <= 0x39 ) {
115 input = input - 0x30; // ASCII to number
116 serial_data[serial_pos++] = input;
118 Serial.print("ignore: ");
119 Serial.println(input, HEX);
122 if ( serial_pos == 2 ) {
123 Serial.print("socket: ");
124 Serial.print(serial_data[0], DEC);
125 Serial.print(" state: ");
126 Serial.println(serial_data[1] ? "on" : "off");
128 if ( serial_data[1] ) { // on
129 switch ( serial_data[0] ) {
131 mySwitch.send("110101011101010000001100");
134 mySwitch.send("110101010111010000001100");
137 mySwitch.send("110101010101110000001100");
140 Serial.print("invalid switch on number ");
141 Serial.println(serial_data[0], DEC);
144 switch ( serial_data[0] ) {
146 mySwitch.send("110101011101010000000011");
149 mySwitch.send("110101010111010000000011");
152 mySwitch.send("110101010101110000000011");
155 Serial.print("invalid switch off number ");
156 Serial.println(serial_data[0], DEC);