使用同步桥小工具的设备间通信
我尝试使用 Blynk 的桥小部件在 wi-fi 设备之间进行通信!
http://docs.blynk.cc/#widgets-other-bridge
目次
配置
A 部分
通过 wi-fi 将 nunchaku 控制器操纵杆的值发送到 blynk 服务器。
- wii nunchuck 控制器
- esp-wroom-02 开发板
- 电池模块
- 锂离子聚合物电池 400mAh
B 部分
接收发送到 Blynk 服务器的操纵杆值, 并移动 led 眼球。
- Neopixel 领导了68件作品使用
- 便宜的 esp8266 开发委员会
混合设置
创建两个项目并获取两个 auth 令牌。由于应用程序不是直接使用的, 因此根本不需要详细设置。
下面是阿杜伊诺的一个闪电侠图书馆。
Https://github.com/blynkkk/blynk-library
arduino ide 程序
A 部分
下面的 wii nunchuck 库被用来连接到微型计算机。
https://github.com/todbot/wiichuck_adapter
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 |
#define BLYNK_PRINT Serial #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> #include <Wire.h> #include "nunchuck_funcs.h" // You should get Auth Token in the Blynk App. char auth[] = "AuthToken for A"; // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "YourNetworkName"; char pass[] = "YourPassword"; // Bridge widget on virtual pin 0 WidgetBridge bridge1(V0); byte joyx,joyy; void setup() { // Debug console Serial.begin(115200); nunchuck_init(); Blynk.begin(auth, ssid, pass); } BLYNK_CONNECTED() { // Token of the hardware B bridge1.setAuthToken("AuthToken for B"); } void loop() { nunchuck_get_data(); joyx = nunchuck_joyx(); // range 29 - 226 joyy = nunchuck_joyy(); // range 29 - 226 Serial.print("joyx: "); Serial.print((byte)joyx,DEC); Serial.print("\tjoyy: "); Serial.println((byte)joyy,DEC); //Send Joystick's values to B(Virtual pin V1) bridge1.virtualWrite(V1, joyx, joyy); Blynk.run(); } |
B 部分
led 库使用了以下内容:
https://github.com/adafruit/Adafruit_NeoPixel
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
#define BLYNK_PRINT Serial #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> #include <Adafruit_NeoPixel.h> #define PIN D4 Adafruit_NeoPixel led = Adafruit_NeoPixel(68, PIN, NEO_GRB + NEO_KHZ800); int blackNum = 24; int pupilNum = 12; uint32_t color; int brightness = 40; byte eyeColor; int LR =0; //Black eye L&R animation int blackLED[15][24] = {{12,32,35,55,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68}, {12,13,31,36,54,55,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68}, {11,13,14,30,37,53,54,56,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68}, {10,11,14,15,29,38,52,53,56,57,68,68,68,68,68,68,68,68,68,68,68,68,68,68}, { 9,10,11,12,15,16,28,33,34,39,51,52,55,56,57,58,68,68,68,68,68,68,68,68}, { 0, 8, 9,10,11,12,13,16,17,27,32,35,40,50,51,54,55,56,57,58,59,67,68,68}, { 0, 1, 7, 8, 9,10,13,14,17,18,26,31,36,41,49,50,53,54,57,58,59,60,66,67}, { 1, 2, 6, 7, 8, 9,14,15,18,19,25,30,37,42,48,49,52,53,58,59,60,61,65,66}, { 2, 3, 5, 6, 7, 8,15,16,19,20,24,29,38,43,47,48,51,52,59,60,61,62,64,65}, { 3, 4, 5, 6, 7,16,17,20,21,23,28,39,44,46,47,50,51,60,61,62,63,64,68,68}, { 4, 5, 6,17,18,21,22,27,40,45,46,49,50,61,62,63,68,68,68,68,68,68,68,68}, { 4, 5,18,19,26,41,48,49,62,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68}, { 4,19,20,25,42,47,48,63,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68}, {20,21,24,43,46,47,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68}, {21,23,44,46,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68}}; //pupil L&R animation int pupilLED[15][12] = {{33,34,68,68,68,68,68,68,68,68,68,68}, {32,33,34,35,68,68,68,68,68,68,68,68}, {12,31,32,33,34,35,36,55,68,68,68,68}, {12,13,30,31,32,33,34,35,36,37,54,55}, {13,14,29,30,31,32,35,36,37,38,53,54}, {14,15,28,29,30,31,36,37,38,39,52,53}, {15,16,27,28,29,30,37,38,39,40,51,52}, {16,17,26,27,28,29,38,39,40,41,50,51}, {17,18,25,26,27,28,39,40,41,42,49,50}, {18,19,24,25,26,27,40,41,42,43,48,49}, {19,20,23,24,25,26,41,42,43,44,47,48}, {20,21,22,23,24,25,42,43,44,45,46,47}, {21,22,23,24,43,44,45,46,68,68,68,68}, {22,23,44,45,68,68,68,68,68,68,68,68}, {22,45,68,68,68,68,68,68,68,68,68,68}}; //Blink animation int eyelid = 0; int eyelidNum[8] = {0,4,8,16,24,34,44,56}; int eyelidLED[56] = {64,65,66,67,58,59,60,61,56,57,62,63,49,50,51,52,47,48,53,54,38,39,40,41,46,55,36,37,42,43,26,27,28,29,35,44,24,25,30,31,15,16,17,18,34,45,23,32,13,14,19,20,6,7,8,9}; int x, y; // You should get Auth Token in the Blynk App. char auth[] = "AuthToken for B"; // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "YourNetworkName"; char pass[] = "YourPassword"; void setup() { // Debug console Serial.begin(115200); Blynk.begin(auth, ssid, pass); led.begin(); led.setBrightness(brightness); // Initial Brightness 40 led.show(); // Initialize all pixels to 'off' color = led.Color(0, 177, 55); //pupil color } uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if(WheelPos < 85) { return led.Color(255 - WheelPos * 3, 0, WheelPos * 3); } if(WheelPos < 170) { WheelPos -= 85; return led.Color(0, WheelPos * 3, 255 - WheelPos * 3); } WheelPos -= 170; return led.Color(WheelPos * 3, 255 - WheelPos * 3, 0); } void blink(int eyelid, int LR) { if (eyelid != 8){ //White eye for(uint16_t i=0; i<led.numPixels(); i++) { led.setPixelColor(i, led.Color(66, 66, 66)); } //Black eye for(uint16_t i=0; i<blackNum; i++) { led.setPixelColor(blackLED[LR][i], color); } //pupil for(uint16_t i=0; i<pupilNum; i++) { led.setPixelColor(pupilLED[LR][i], led.Color(0, 0, 66)); } //eyelid for(int i=0; i < eyelidNum[eyelid]; i++) { led.setPixelColor(eyelidLED[i], 0); } } else if (eyelid == 8){ led.clear(); } led.show(); } BLYNK_WRITE(V1){ x = param[0].asInt(); y = param[1].asInt(); Serial.print("joyx: "); Serial.print(x); Serial.print(" joyy: "); Serial.println(y); //Blink on joystick y axis eyelid = map(y, 29, 130, 8, 0); if (eyelid > 8) { eyelid = 8; } if (eyelid < 0) { eyelid = 0; } //Joystick x-axis pupil left and right LR = map(x, 29, 226, 0, 14); if (LR > 14) { LR = 14; } if (LR < 0) { LR = 0; } blink(eyelid, LR); } void loop() { Blynk.run(); } |
操作
使用 blynk, 您可以轻松地在设备之间进行通信!此外, 通信设置等。到服务器是不自觉的, 在所有容易
这是一个功能, 似乎传播各种可能性!