User Tools

Site Tools


electronics_at_component_level

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
electronics_at_component_level [2018/09/15 09:48]
c0rn3j [IR]
electronics_at_component_level [2019/08/27 11:31] (current)
c0rn3j [LED strips]
Line 10: Line 10:
 Do not leave the iron on when you are not using it. Do not leave the iron on when you are not using it.
  
-Clean the tip by applying solder, wiping it clean on a sponge or steel wool and then coat it with a thin layer of solder to prevent oxidation before you turn it off and leave it.+Clean the tip by applying solder, wiping it clean on a sponge or steel wool and then coat it with a thin layer of solder to prevent oxidation before you turn it off and leave it, or coat it right after turning it off.
  
 If you use a sponge, make sure it's damp but not soaked. If you use a sponge, make sure it's damp but not soaked.
Line 24: Line 24:
 ## LED strips ## LED strips
  
-LED strips from "worst" to "best". Price is according to that.+LED strips from "best" to "worst". Price is according to that.
  
-WS2812B ​> APA102C > APA102+SK9822 =~ APA102 ​> APA102C > WS2812B
  
 ## Capacitors ## Capacitors
Line 82: Line 82:
 You can use the number notation (GPIO10 is defined as '​10'​) or the pin notation, like D0. You can use the number notation (GPIO10 is defined as '​10'​) or the pin notation, like D0.
  
 +<code C++>
   void setup() {   void setup() {
     pinMode(D0, OUTPUT);     pinMode(D0, OUTPUT);
Line 91: Line 92:
     delay(1000); ​           // wait for 1 second.     delay(1000); ​           // wait for 1 second.
   }   }
 +</​code>​
  
 Upload it to the board, it should boot up and the blue LED should start blinking. Upload it to the board, it should boot up and the blue LED should start blinking.
Line 102: Line 104:
 Re-connect the resistor from the 3v3 pin to the SD3 one (GPIO10) and replace the code with this: Re-connect the resistor from the 3v3 pin to the SD3 one (GPIO10) and replace the code with this:
  
 +<code C++>
   const short int LED1 = 10;    const short int LED1 = 10; 
   void setup() {   void setup() {
Line 116: Line 119:
     delay(1000); ​           // wait for 1 second.     delay(1000); ​           // wait for 1 second.
   }   }
 +</​code>​
   ​   ​
 Now it should blink! And since we added serial connection and some debugging output, we should be able to connect to it via some software that can read serial, for example '​screen'​. Note that 115200 is the baud rate, affecting how fast you can send/​receive data. Now it should blink! And since we added serial connection and some debugging output, we should be able to connect to it via some software that can read serial, for example '​screen'​. Note that 115200 is the baud rate, affecting how fast you can send/​receive data.
Line 125: Line 129:
 Now let's make the LED Wi-Fi controllable! Same physical setup, different code. Just change the SSID and password in the example: Now let's make the LED Wi-Fi controllable! Same physical setup, different code. Just change the SSID and password in the example:
  
-<​code>​+<​code ​C++>
 #include <​ESP8266WiFi.h>​ #include <​ESP8266WiFi.h>​
  
-const short int LED1 = 10; +const short int LED1 = 10;
  
-const char* ssid = "mywifiname"; +const char* ssid = "ssid"; 
-const char* password = "securepassword";+const char* password = "password";
 WiFiServer server(80); WiFiServer server(80);
  
 void setup() { void setup() {
-  ​Serial.begin(115200); ​       // connect to the serial port + Serial.begin(115200);​ 
-  pinMode(LED1,​ OUTPUT); + pinMode(LED1,​ OUTPUT); 
-  // WiFi.mode(m):​ set mode to WIFI_AP, WIFI_STA, or WIFI_AP_STA. + // WiFi.mode(m):​ set mode to WIFI_AP, WIFI_STA, or WIFI_AP_STA. 
-  WiFi.mode(WIFI_STA);​ + WiFi.mode(WIFI_STA);​ 
-  delay(10);​ + delay(10);​ 
-  WiFi.begin(ssid,​ password);+ WiFi.begin(ssid,​ password);
  
-  ​while (WiFi.status() != WL_CONNECTED) { + while (WiFi.status() != WL_CONNECTED) { 
-    Serial.println("​Wi-Fi not connected, retrying... "); + Serial.println("​Wi-Fi not connected, retrying... "); 
-    delay(500); // Do not use this delay in SoftAP mode + delay(500); // Do not use this delay in SoftAP mode 
-  +
-  // Start the server + // Start the wifi server 
-  server.begin();​+ server.begin();​
  
-  ​Serial.println("​IP address: "); + Serial.println("​IP address: "); 
-  Serial.println(WiFi.localIP()); ​+ Serial.println(WiFi.localIP());​
 } }
  
 void loop() { void loop() {
-  ​if(WiFi.status() != WL_CONNECTED) { + if(WiFi.status() != WL_CONNECTED) { 
-    Serial.println("​Wi-Fi not connected, retrying... "); + Serial.println("​Wi-Fi not connected, retrying... "); 
-    delay(500); // Do not use this delay in SoftAP mode + delay(500); // Do not use this delay in SoftAP mode 
-  +
-  WiFiClient client = server.available();​ + WiFiClient client = server.available();​ 
-  if (!client) { + if (!client) { 
-//    Serial.println("​No client connected, suiciding."​);​ + //​Serial.println("​No client connected, suiciding."​);​ 
-    return; + return; 
-  } + }
- +
-  int insanity = 0; +
-  // Wait until the client sends some data +
-  while (!client.available()) { +
-    insanity++;​ +
-    if (insanity == 1000) +
-    { +
-      Serial.println("​And nobody came..."​);​ +
-      return; +
-    } +
-    delay(1); +
-    Serial.println("​Waiting for client to send data."​);​ +
-//    client = server.available();​ // Check if the connection didn't fuck up, if yes, kill it. +
-//    if (!client) { +
-//    return; +
-//    } +
-  } +
-  Serial.println("​Client available, receiving data..."​);  ​+
  
-  ​// Read the first line of the request + int insanity = 0; 
-  ​String request ​= client.readStringUntil('​\r'​); + // Wait until the client sends some data 
-  client.flush();+ while (!client.available()) { 
 + insanity++;​ 
 + if (insanity ​== 1000) { 
 + Serial.println("​And nobody came..."​);​ 
 + return;​ 
 +
 + delay(1);​ 
 + Serial.println("​Waiting for client ​to send data."); 
 + //client = server.available(); // Check if the connection didn't fuck up, if yes, kill it. 
 + //if (!client) { 
 + //​return;​ 
 + //} 
 +
 + Serial.println("​Client available, receiving data..."​);
  
-  ​// Match the request + // Read the first line of the request 
-  if (request.indexOf("/​OFF"​) != -1)  + String ​request ​= client.readStringUntil('​\r'​); 
-    digitalWrite(LED1,​ LOW); + client.flush();
-  if (request.indexOf("/​ON"​) != -1) +
-    digitalWrite(LED1, HIGH);+
  
-  ​// Return the response + // Match the request 
-  String html = String("​HTTP/​1.1 200 OK\r\n"​) ++ if (request.indexOf("/​OFF"​) != -1) { 
 + digitalWrite(LED1,​ LOW); 
 +
 + if (request.indexOf("/​ON"​) != -1) { 
 + digitalWrite(LED1,​ HIGH); 
 +
 + // Return the response 
 + String html = String("​HTTP/​1.1 200 OK\r\n"​) +
                 "​Content-Type:​ text/​html\r\n"​ +                 "​Content-Type:​ text/​html\r\n"​ +
                 "​\r\n"​ +                 "​\r\n"​ +
Line 228: Line 232:
                 "</​body>"​ +                 "</​body>"​ +
                 "</​html>";​                 "</​html>";​
-  ​client.print(html);​ + client.print(html);​ 
-  delay(1);+ delay(1);
 } }
 </​code>​ </​code>​
Line 238: Line 242:
 ### IR ### IR
  
-Now that you know enough to get going, time to dive into something fun, IR. +Now that you know enough to get going, time to dive into something fun, IR. Let's make a thing that can both receive and send. 
 + 
 +You'll need a 2-pin IR LED, 3-pin 1838 IR receiver, 2N2222 NPN transistor, 100 Ohm resistor and some wires. 
 + 
 +{{::​ir_rec_send.png?​800|}} 
 + 
 +You will need to setup the IR library for ESP8266 - https://​github.com/​markszabo/​IRremoteESP8266
  
 Keep in mind that at least on the NodeMCU board linked in the doc with stuff to buy you can't use GPIO 1,​3,​9,​10,​15,​16 for IR receive(and possibly send), the limitations are mostly explained [here](https://​tttapa.github.io/​ESP8266/​Chap04%20-%20Microcontroller.html). Keep in mind that at least on the NodeMCU board linked in the doc with stuff to buy you can't use GPIO 1,​3,​9,​10,​15,​16 for IR receive(and possibly send), the limitations are mostly explained [here](https://​tttapa.github.io/​ESP8266/​Chap04%20-%20Microcontroller.html).
Line 244: Line 254:
 I used this code to test which GPIOs I can use for receiving: I used this code to test which GPIOs I can use for receiving:
  
-<​code>​+<​code ​C++>
 #include <​ESP8266WiFi.h>​ #include <​ESP8266WiFi.h>​
  
Line 262: Line 272:
 #include <​ir_Toshiba.h>​ #include <​ir_Toshiba.h>​
 #include <​ir_Trotec.h>​ #include <​ir_Trotec.h>​
- 
- 
-#define IR_BPLUS ​ 0xFFA05F ​ //  
-#define IR_BMINUS 0xFF20DF ​ //  
-#define IR_OFF ​   0xFF609F ​ //  
-#define IR_ON     ​0xFFE01F ​ //  
-#define IR_R    0xFF906F ​ //  
-#define IR_G    0xFF10EF ​ //  
-#define IR_B    0xFF50AF ​ //  
-#define IR_W    0xFFD02F //  
-#define IR_B1   ​0xFFB04F ​ //  
-#define IR_B2   ​0xFF30CF ​ //  
-#define IR_B3   ​0xFF708F ​ //  
-#define IR_FLASH ​ 0xFFF00F ​ //  
-#define IR_B4   ​0xFFA857 ​ //  
-#define IR_B5   ​0xFF28D7 ​ //  
-#define IR_B6   ​0xFF6897 ​ //  
-#define IR_STROBE 0xFFE817 ​ //  
-#define IR_B7   ​0xFF9867 ​ //  
-#define IR_B8   ​0xFF18E7 ​ //  
-#define IR_B9   ​0xFF58A7 ​ //  
-#define IR_FADE ​  ​0xFFD827 ​ //  
-#define IR_B10 ​   0xFF8877 ​ //  
-#define IR_B11 ​   0xFF08F7 ​ //  
-#define IR_B12 ​   0xFF48B7 ​ //  
-#define IR_SMOOTH 0xFFC837 ​ //  
-#define IR_HOLD ​  ​0xFFFFFFFF // 
- 
-const short int LED1 = 10;  
  
 const char* ssid = "​ssid";​ const char* ssid = "​ssid";​
Line 301: Line 282:
  
 void setup() { void setup() {
-  ​Serial.begin(115200); ​       // connect to the serial port + Serial.begin(115200);​ 
-  ​pinMode(LED1, OUTPUT);+ irrecv.enableIRIn();
  
-  irrecv.enableIRIn();​ // Start the receiver + // WiFi.mode(m):​ set mode to WIFI_AP, WIFI_STA, or WIFI_AP_STA. 
-     + WiFi.mode(WIFI_STA);​ 
-  ​// WiFi.mode(m):​ set mode to WIFI_AP, WIFI_STA, or WIFI_AP_STA. + delay(10);​ 
-  WiFi.mode(WIFI_STA);​ + WiFi.begin(ssid,​ password);
-  delay(10);​ +
-  WiFi.begin(ssid,​ password);+
  
-  ​while (WiFi.status() != WL_CONNECTED) { + while (WiFi.status() != WL_CONNECTED) { 
-    Serial.println("​Wi-Fi not connected, retrying... "); + Serial.println("​Wi-Fi not connected, retrying... "); 
-    delay(500); // Do not use this delay in SoftAP mode + delay(500); // Do not use this delay in SoftAP mode 
-  +
-  // Start the server + // Start the wifi server 
-  server.begin();​+ server.begin(); 
 + Serial.println("​IP address: "); 
 + Serial.println(WiFi.localIP());
  
-  ​Serial.println("IP address: "); + Serial.print("RECV_PIN now: "); 
-  Serial.println(WiFi.localIP()); + Serial.println(RECV_PIN);
 } }
- 
 void loop() { void loop() {
 + if (irrecv.decode(&​results)) {
 + Serial.println((long int)results.value,​ HEX);
 + irrecv.resume();​ // Receive the next value
 + return; // Kill the cycle
 + }
 + if(WiFi.status() != WL_CONNECTED) {
 + Serial.println("​Wi-Fi not connected, retrying... ");
 + delay(500);​ // Do not use this delay in SoftAP mode
 + }
 + WiFiClient client = server.available();​
 + if (!client) {
 +//​ Serial.println("​No client connected, suiciding."​);​
 + return;
 + }
  
-    if (irrecv.decode(&​results)) { + int insanity = 0; 
-      Serial.println((long int)results.value,​ HEX); + // Wait until the client sends some data 
- + while (!client.available()) { 
-/*     ​switch((long int)results.value) { + insanity++;​ 
-      case 0x20DFF10E : RollUp(32000);​ break; + if (insanity == 1000) { 
-      case 0x20DF0DF2 : RollUp(1000);​ break; + Serial.println("​And nobody came..."​);​ 
-      case 0x20DF5DA2 : RollDown(1000);​ break; + return; 
-      case 0x20DF718E : RollDown(28000);​ break; +
-     ​default : break; + delay(1); 
-      } + Serial.println("​Waiting for client to send data."​);​ 
-      */ +
-     ​irrecv.resume();​ // Receive the next value + Serial.println("​Client available, receiving data..."​);​
-     ​return;​ // Kill the cycle  +
-    } +
- +
-  if(WiFi.status() != WL_CONNECTED) { +
-    Serial.println("​Wi-Fi not connected, retrying... "); +
-    delay(500); // Do not use this delay in SoftAP mode +
-  } +
-  WiFiClient client = server.available();​ +
-  if (!client) { +
-//    Serial.println("​No client connected, suiciding."​);​ +
-    return; +
-  } +
- +
-  ​int insanity = 0; +
-  // Wait until the client sends some data +
-  while (!client.available()) { +
-    insanity++;​ +
-    if (insanity == 1000) +
-    ​+
-      Serial.println("​And nobody came..."​);​ +
-      return; +
-    +
-    delay(1); +
-    Serial.println("​Waiting for client to send data."​);​ +
-//    client = server.available();​ // Check if the connection didn't fuck up, if yes, kill it. +
-//    if (!client) { +
-//    return; +
-//    } +
-  ​+
-  Serial.println("​Client available, receiving data..."​); ​ +
  
-  ​// Read the first line of the request + // Read the first line of the request 
-  String request = client.readStringUntil('​\r'​);​ + String request = client.readStringUntil('​\r'​);​ 
-  client.flush();​+ client.flush();​
  
-  ​// Match the request + // Match the request 
-  if (request.indexOf("/​OFF") != -1)  + if (request.indexOf("/​NEXT_PIN") != -1) { 
-    ​digitalWrite(LED1, LOW); + nextPin(); 
-  if (request.indexOf("/​ON"​) != -1) + } 
-    digitalWrite(LED1,​ HIGH); + // Return the response 
-  if (request.indexOf("/​TEST"​) != -1) + String html = String("​HTTP/​1.1 200 OK\r\n"​) +
-    testFunction();​ +
-    ​ +
-  // Return the response +
-  String html = String("​HTTP/​1.1 200 OK\r\n"​) ++
                 "​Content-Type:​ text/​html\r\n"​ +                 "​Content-Type:​ text/​html\r\n"​ +
                 "​\r\n"​ +                 "​\r\n"​ +
Line 411: Line 371:
                 "</​head>"​ +                 "</​head>"​ +
                 "<​body>"​ +                 "<​body>"​ +
-                "<a href=\"/​ON\"><​div class=\"​button big-btn\">​ON</​div></​a>"​ + +                "<a href=\"/​NEXT_PIN\"><​div class=\"​button big-btn\">​NEXT_PIN</​div></​a>"​ +
-                "<a href=\"/​OFF\"><​div class=\"​button big-btn\">​OFF</​div></​a>"​ + +
-                "<a href=\"/​TEST\"><​div class=\"​button big-btn\">​TEST</​div></​a>"​ ++
                 "</​body>"​ +                 "</​body>"​ +
                 "</​html>";​                 "</​html>";​
-  ​client.print(html);​ + client.print(html);​ 
-  delay(1);+ delay(1);
 } }
  
-  ​void testFunction() { +void nextPin() { 
-    irrecv.disableIRIn();​ + irrecv.disableIRIn();​ 
-    delay(100);​ + delay(100);​ 
-    RECV_PIN = RECV_PIN+1; //IR IN + RECV_PIN = RECV_PIN+1; //IR IN 
-    Serial.println("​RECV_PIN now: "); + Serial.print("​RECV_PIN now: "); 
-    Serial.print(RECV_PIN);​ + Serial.println(RECV_PIN);​ 
- + IRrecv irrecv(RECV_PIN);​ 
-    ​IRrecv irrecv(RECV_PIN);​ + decode_results results; 
-    decode_results results; + irrecv.enableIRIn();​ // Start the receiver 
-    irrecv.enableIRIn();​ // Start the receiver + delay(100);​ 
-    delay(100);​ +}
- +
-  ​} +
 </​code>​ </​code>​
electronics_at_component_level.1537004882.txt.gz · Last modified: 2018/09/15 09:48 by c0rn3j