Snippets

Peter Scargill Nano Peripheral IR (IR section untested, input always uses 2, output needs 3 if used)

Updated by Peter Scargill

File snippet.txt Modified

  • Ignore whitespace
  • Hide word diff
-// This update May 2018 Peter Scargill
+// This update September 2018 Peter Scargill
 //
 // So this is a relatively simple,cheap peripheral using a £1.50 NANO board from China.
 // It is supported by my ESP8266 software but as it is an I2c slave you could run it
 //
 // if and when IR output is used - this has to be gpio pin 3.
 //
-// As a guide you could use 3,5,6 and 9, 10 and 11 for PWM (unless you use these pins for general IO)
-// you can use 2, 4, 7, 8, 12 and 13 as input/output (I tried using 0 and 1 for GPIO - no go - 0 flashes
+// As a guide you could use 3,5,6 and 9, 10 and 11 for PWM (unless you use these pins for general IO or 3 for IR out)
+// you can use 4, 7, 8, 12 and 13 as input/output (I tried using 0 and 1 for GPIO - no go - 0 flashes. 2 is IR input on this version, can't 
+// use for other purposes.
 // on power up - 1 has pullup - best just avoid using these two for general IO - use for serial IO).
 // remember 13 probably has a LED attached on the board so best used for output.
 //
 // The board becomes a simple i2c SLAVE - default (programmable) device number 9 - reads instructions from
 // master and either sets outputs or returns inputs accordingly.
 //
-// There is also now a soft fade option for PWM, a tone generator and Dallas temperature chip support for up to 2 chips.
+// There is also now a soft fade option for PWM (up to 6 PWM channels), a tone generator and Dallas temperature chip support for up to 2 chips.
 // Here I use a simplified version of my DS18B20 code from years back. This starts the conversion at the END
 // of the code - so the first value is rubbish - read the blog as this is hidden - and there are no delays. On the assumption of one chip
 // per pin, no need for search either!
 // function that executes whenever data is requested by master
 // this function is registered as an event, see setup()
 void requestEvent() {
-  retparams[5] = busy;
+  retparams[5]=busy;
   Wire.write(retparams, 6);
 }
 
       }
       myservos[params[1]].write(params[2]);
       break;
-    case FADE:
+      
+    case FADE:  // node-red and esp-go {nano:9,12,3,255} for a single output, for rgb on 3,5 and 6 assuming decice default 9)
+                // {nano:9,12,3,255;nano:9,12,5,80;nano:9,12,6,10}
       if (ports[params[1]] != 4) {
         ports[params[1]] = 4;
         pinMode(params[1], OUTPUT);
Updated by Peter Scargill

File snippet.txt Modified

  • Ignore whitespace
  • Hide word diff
+// This update May 2018 Peter Scargill
+//
 // So this is a relatively simple,cheap peripheral using a £1.50 NANO board from China.
 // It is supported by my ESP8266 software but as it is an I2c slave you could run it
-// from anything able to handle I2c. For example I have found that some of the NanoPi units
+// from anything able to handle I2c. For example I have found that some of the NanoPi SBCs
 // are not too keen on even a bright LED on their IO pins and from an operating
 // system like Linux, getting PWM on several pins is just not on... so - plug in this device
 // (default ID 9) with pullups (always needed for I2c) and you can gain PWM, ADC
-// and general IO for very little money.
+// and general IO for very little money or better, use with ESP-GO to add veryu inexpensive funtionality to the ESP8266.
 //
 // This version supports IR on pin 2 - you need this - follow installation instructions properly
 // https://github.com/cyborg5/IRLib2
+//
 // Pin 2 is used for IR in using a standard 38khz type IR receiver.  PWM not affected.
-// Note however the RETURN values have changed - now 6 bytes with the 5th being status.
+// Note the RETURN information - 6 bytes with the 5th being status.
 // in the case of IR, 0,1,2,3 are 32 bit value, 4 is protocol.  If protocol is zero, nothing there.
 // 32 byte circular buffer.
-// if and when IR out is set up - this has to be pin 3.
 //
-// So as a guide you could use 3,5,6 and 9, 10 and 11 for PWM (unless you use these pins for general IO)
-// you can use 2, 4, 7, 8, 12 and 13 as input/output (I tried using 0 and 1 - no go 0 flashes
-// on power up - 1 has pullup - best just avoid for GPIO 0 - use for serial IO).
+// if and when IR output is used - this has to be gpio pin 3.
+//
+// As a guide you could use 3,5,6 and 9, 10 and 11 for PWM (unless you use these pins for general IO)
+// you can use 2, 4, 7, 8, 12 and 13 as input/output (I tried using 0 and 1 for GPIO - no go - 0 flashes
+// on power up - 1 has pullup - best just avoid using these two for general IO - use for serial IO).
 // remember 13 probably has a LED attached on the board so best used for output.
-// You could use A0 (14), A1 (15), A2 (16) and A3 (17) as analog in - possibly
-// A6 (20) and A7 (21) if available. Set to 1.1v full scale.
+//
+// You could use A0 (14), A1 (15), A2 (16) and A3 (17) as analog or digital inputs - possibly
+// A6 (20) and A7 (21) if available on your board. Set to 1.1v full scale.
 // A4 and A5 are used for the I2c where A4 is SDA and A5 is SCL.
-// On the blog at https://tech.scargill.net you'll see several examples of using I2c from various boards.
+//
+// On the blog at https://tech.scargill.net you'll see several examples of using I2c.
 //
 // Late addition - servos - any of the pins 2-13 can be a servo. command is 11 - so device, command, pin, value
 // Send value 255 to disconnect a servo and note if ANY pin is set up as a servo you lose PWM options on pins 9 and 10.
 // Just disconnect all individually to get the PWM back (normally all disconnected at power up).
 // Values 0-180 but this varies with different servos. Mine buzzed at 0 !! See Arduino Servo library
 //
-// A simple i2c SLAVE - default device number 9 - reads instructions from
+// The board becomes a simple i2c SLAVE - default (programmable) device number 9 - reads instructions from
 // master and either sets outputs or returns inputs accordingly.
 //
-// Not yet used but check out the enable interrupt library here
-// https://github.com/GreyGnome/EnableInterrupt
-// could be used for edge-triggered interrupts on any pin for pulse counting
-//
-// There is also now a soft fade option for PWM, a tone generator and Dallas temperatur chip support for up to 2 chips.
+// There is also now a soft fade option for PWM, a tone generator and Dallas temperature chip support for up to 2 chips.
 // Here I use a simplified version of my DS18B20 code from years back. This starts the conversion at the END
 // of the code - so the first value is rubbish - read the blog as this is hidden - and there are no delays. On the assumption of one chip
 // per pin, no need for search either!
 
-// This version returns 6 bytes - the LAST one is a status byte - 1 if busy. For IR bytes 0,1,2,3 are value, 4 is protocol. Simply send that out 
+// This version returns 6 bytes - the LAST one is a status byte - 1 if busy. For IR, bytes 0,1,2,3 are value, 4 is protocol. Simply send that out 
 // for transmission...  I'm using serial for debug right now - so can't use serial command - simply scrap that if you want to use serial out.
 //
 #include <EEPROM.h>
     default: break;
   }
   busy = 0;
-}
+}
Updated by Peter Scargill

File snippet.txt Modified

  • Ignore whitespace
  • Hide word diff
 #define DALLAS2 16
 #define IRIN 17
 #define IROUT 18
+#define SETSERIAL 20 // 0 means turn serial off, by default on. Other values- 1=300, 2=1200, 3=2400, 4=9600, 5=28800, 6=57600, 7=115200 baud
 
 #define STRUCTBASE 0
 
       irout=params[2] + (params[3]<<8) + (params[4]<<16) + (params[5]<<24);
       mySender.send(params[1],irout,params[6]);
       break;
-      
+
+    case SETSERIAL:
+          switch (params[1]) {
+            case 0 : Serial.end(); break;
+            case 1 : Serial.begin(300); break;
+            case 2 : Serial.begin(1200); break;
+            case 3 : Serial.begin(2400); break;
+            case 4 : Serial.begin(9600); break;
+            case 5 : Serial.begin(28800); break;
+            case 6 : Serial.begin(57600); break;
+            case 7 : Serial.begin(115200); break;
+            default: break;            
+          }
+          break;
+    
     default: break;
   }
   busy = 0;
Updated by Peter Scargill

File snippet.txt Modified

  • Ignore whitespace
  • Hide word diff
 #define PORTOUT 8
 #define PORTIN 9
 #define SEROUT 10
-#define SERVO 11   /// value 255 disconnects.... - normally use 0-180
-#define FADE 12
+#define SERVO 11   // value 255 disconnects.... - normally use 0-180
+#define FADE 12    // pwm but you set desired colour, software soft fades from current to desired
 #define TONE 13
 #define NOTONE 14
 #define DALLAS1 15
Updated by Peter Scargill

File snippet.txt Modified

  • Ignore whitespace
  • Hide word diff
 // You could use A0 (14), A1 (15), A2 (16) and A3 (17) as analog in - possibly
 // A6 (20) and A7 (21) if available. Set to 1.1v full scale.
 // A4 and A5 are used for the I2c where A4 is SDA and A5 is SCL.
-// On the blog at http://tech.scargill.net you'll see several examples of using I2c from various boards.
+// On the blog at https://tech.scargill.net you'll see several examples of using I2c from various boards.
 //
 // Late addition - servos - any of the pins 2-13 can be a servo. command is 11 - so device, command, pin, value
 // Send value 255 to disconnect a servo and note if ANY pin is set up as a servo you lose PWM options on pins 9 and 10.
  1. 1
  2. 2
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.