├── ADS1147 ├── ADS1147.cpp ├── ADS1147.h ├── examples │ └── Example │ │ └── Example.ino ├── library.json └── library.properties ├── ADS7846 ├── ADS7846.cpp ├── ADS7846.h ├── examples │ └── Example │ │ └── Example.ino ├── library.json └── library.properties ├── DAC8760 ├── DAC8760.cpp ├── DAC8760.h ├── examples │ ├── Example │ │ └── Example.ino │ ├── Freq2Volt │ │ └── Freq2Volt.ino │ └── Freq2VoltAdv │ │ └── Freq2VoltAdv.ino ├── library.json └── library.properties ├── DS1307 ├── DS1307.cpp ├── DS1307.h ├── examples │ └── Example │ │ └── Example.ino ├── library.json └── library.properties ├── DisplayI2C ├── DisplayI2C.cpp ├── DisplayI2C.h ├── cmd.h ├── library.json └── library.properties ├── DisplaySPI ├── DisplaySPI.cpp ├── DisplaySPI.h ├── cmd.h ├── library.json └── library.properties ├── DisplayUART ├── DisplayUART.cpp ├── DisplayUART.h ├── cmd.h ├── library.json └── library.properties ├── GraphicsLib ├── BMPheader.h ├── GraphicsLib.cpp ├── GraphicsLib.h ├── examples │ ├── ChuckNorris │ │ └── ChuckNorris.ino │ ├── DataVisualization │ │ └── DataVisualization.ino │ ├── Demo │ │ └── Demo.ino │ ├── GameOfLife │ │ └── GameOfLife.ino │ └── Paint │ │ └── Paint.ino ├── font_10x16.c ├── font_12x16.c ├── font_12x20.c ├── font_16x26.c ├── font_4x6.c ├── font_5x12.c ├── font_5x8.c ├── font_6x10.c ├── font_6x8.c ├── font_7x12.c ├── font_8x12.c ├── font_8x14.c ├── font_8x8.c ├── fonts.h ├── library.json └── library.properties ├── LCD_BackPack ├── LCD_BackPack.h ├── examples │ └── SerLCD │ │ ├── SerLCD.ino │ │ └── SerLCD.md ├── library.json └── library.properties ├── MCP2515 ├── MCP2515.cpp ├── MCP2515.h ├── examples │ └── Example │ │ └── Example.ino ├── library.json └── library.properties ├── MI0283QT2 ├── MI0283QT2.cpp ├── MI0283QT2.h ├── library.json └── library.properties ├── MI0283QT9 ├── MI0283QT9.cpp ├── MI0283QT9.h ├── library.json └── library.properties ├── README.md ├── RV8523 ├── RV8523.cpp ├── RV8523.h ├── examples │ ├── Example │ │ └── Example.ino │ └── SetClock │ │ └── SetClock.ino ├── library.json └── library.properties ├── RedFly ├── README.md ├── RedFly.cpp ├── RedFly.h ├── RedFlyClient.cpp ├── RedFlyClient.h ├── RedFlyCommands.h ├── RedFlyNBNS.cpp ├── RedFlyNBNS.h ├── RedFlyServer.cpp ├── RedFlyServer.h ├── examples │ ├── Adhoc │ │ └── Adhoc.ino │ ├── EchoTest │ │ └── EchoTest.ino │ ├── FWupdate │ │ └── FWupdate.ino │ ├── Infrastructure │ │ └── Infrastructure.ino │ ├── NBNS │ │ └── NBNS.ino │ ├── NTP │ │ └── NTP.ino │ ├── Paint │ │ └── Paint.ino │ ├── TwitterRSSReader │ │ └── TwitterRSSReader.ino │ ├── TwitterTest │ │ └── TwitterTest.ino │ ├── TwitterTest_Socket │ │ └── TwitterTest_Socket.ino │ ├── TwitterWriter │ │ └── TwitterWriter_Socket.ino │ ├── UDP │ │ └── UDP.ino │ ├── WLANScan │ │ └── WLANScan.ino │ ├── WebClient │ │ └── WebClient.ino │ ├── WebClient_Socket │ │ └── WebClient_Socket.ino │ ├── WebServer │ │ └── WebServer.ino │ ├── WebServer2 │ │ └── WebServer2.ino │ ├── WebServer_Socket │ │ ├── WebServer_Socket.ino │ │ └── conn_test.htm │ └── XivelyClient │ │ └── XivelyClient.ino ├── library.json └── library.properties ├── RotaryEncoder ├── RotaryEncoder.cpp ├── RotaryEncoder.h ├── examples │ └── Example │ │ └── Example.ino ├── library.json └── library.properties ├── S65L2F50 ├── S65L2F50.cpp ├── S65L2F50.h ├── library.json └── library.properties ├── S65LPH88 ├── S65LPH88.cpp ├── S65LPH88.h ├── library.json └── library.properties ├── S65LS020 ├── S65LS020.cpp ├── S65LS020.h ├── library.json └── library.properties ├── SSD1331 ├── SSD1331.cpp ├── SSD1331.h ├── library.json └── library.properties ├── TinyWire ├── TinyWireM.cpp ├── TinyWireM.h ├── TinyWireS.cpp ├── TinyWireS.h ├── USI_TWI_Master.c ├── USI_TWI_Master.h ├── USI_TWI_Slave.c ├── USI_TWI_Slave.h ├── examples │ ├── Tiny85_I2C_Slave │ │ └── Tiny85_I2C_Slave.ino │ └── Tiny85_Temp │ │ └── Tiny85_Temp.ino ├── library.json ├── library.properties └── readme.txt ├── digitalWriteFast ├── digitalWriteFast.h ├── examples │ └── Example │ │ └── Example.ino ├── library.json └── library.properties ├── license.txt ├── light_WS2812 ├── WS2812.cpp ├── WS2812.h ├── cRGB.h ├── examples │ ├── Blinky │ │ └── Blinky.ino │ ├── RGB_Clock │ │ └── RGB_Clock.ino │ ├── fade_rgb │ │ └── fade_rgb.ino │ └── rainbow │ │ └── rainbow.ino ├── library.json ├── library.properties ├── license.txt ├── light_ws2812.cpp └── readme.txt └── mSD_Shield ├── README.md ├── examples ├── BMPDemo │ ├── BMPDemo.ino │ └── image.bmp ├── DataLogger │ └── DataLogger.ino ├── RTC │ └── RTC.ino └── ReadWrite │ └── ReadWrite.ino ├── library.json ├── library.properties └── mSD_Shield.h /ADS1147/ADS1147.h: -------------------------------------------------------------------------------- 1 | #ifndef ADS1147_h 2 | #define ADS1147_h 3 | 4 | 5 | #include 6 | 7 | 8 | class ADS1147 9 | { 10 | public: 11 | ADS1147(); 12 | uint_least8_t begin(uint_least8_t drate, uint_least8_t gain, uint_least16_t current); 13 | uint_least8_t begin(void); 14 | int_least16_t read(uint_least8_t chn); 15 | 16 | private: 17 | int_least16_t rd_data(void); 18 | void wr_cmd(uint_least8_t cmd); 19 | uint_least8_t rd_reg(uint_least8_t reg); 20 | void wr_reg(uint_least8_t reg, uint_least8_t data); 21 | uint_least8_t rd_spi(void); 22 | void wr_spi(uint_least8_t data); 23 | }; 24 | 25 | 26 | #endif //ADS1147_h 27 | -------------------------------------------------------------------------------- /ADS1147/examples/Example/Example.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ADS1147 ADC Example 3 | 4 | CS - D10 5 | SDI - D11/MOSI 6 | SDO - D12/MISO 7 | CLK - D13/CLK 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | ADS1147 adc; 16 | 17 | 18 | void setup() 19 | { 20 | int32_t i; 21 | 22 | //init Serial port 23 | Serial.begin(9600); 24 | while(!Serial); //wait for serial port to connect - needed for Leonardo only 25 | 26 | //init DAC 27 | Serial.println("Init..."); 28 | adc.begin(20, 4, 1000); //20 SPS, Gain 4, 1000 uA 29 | 30 | i = adc.read(0x01); //read 0+1 31 | Serial.println(i, DEC); 32 | i = adc.read(0x23); //read 2+3 33 | Serial.println(i, DEC); 34 | } 35 | 36 | 37 | void loop() 38 | { 39 | //do nothing 40 | } 41 | -------------------------------------------------------------------------------- /ADS1147/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ADS1147", 3 | "version": "1.0.0", 4 | "keywords": "spi, adc, analog, input, converter, signal", 5 | "description": "ADS1147 ADC (Analog-Digital-Converter)", 6 | "include": "ADS1147", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "dependencies": 13 | { 14 | "name": "digitalWriteFast", 15 | "frameworks": "arduino" 16 | }, 17 | "frameworks": "arduino", 18 | "platforms": "atmelavr" 19 | } 20 | -------------------------------------------------------------------------------- /ADS1147/library.properties: -------------------------------------------------------------------------------- 1 | name=ADS1147 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=ADS1147 ADC (Analog-Digital-Converter) 6 | paragraph=ADS1147 ADC (Analog-Digital-Converter) 7 | category=Signal Input/Output 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /ADS7846/ADS7846.h: -------------------------------------------------------------------------------- 1 | #ifndef ADS7846_h 2 | #define ADS7846_h 3 | 4 | 5 | #include 6 | //#include "GraphicsLib.h" 7 | //#include "MI0283QT2.h" 8 | //#include "MI0283QT9.h" 9 | 10 | 11 | typedef struct 12 | { 13 | uint_least32_t x; 14 | uint_least32_t y; 15 | } CAL_POINT; //calibration points for touchpanel 16 | 17 | 18 | typedef struct 19 | { 20 | uint_least32_t a; 21 | uint_least32_t b; 22 | uint_least32_t c; 23 | uint_least32_t d; 24 | uint_least32_t e; 25 | uint_least32_t f; 26 | uint_least32_t div; 27 | } CAL_MATRIX; //calibration matrix for touchpanel 28 | 29 | 30 | class ADS7846 31 | { 32 | public: 33 | uint_least16_t lcd_orientation; //lcd_orientation 34 | uint_least16_t lcd_x, lcd_y; //calibrated pos (screen) 35 | uint_least16_t tp_x, tp_y; //raw pos (touch panel) 36 | uint_least16_t tp_last_x, tp_last_y; //last raw pos (touch panel) 37 | CAL_MATRIX tp_matrix; //calibrate matrix 38 | uint_least8_t pressure; //touch panel pressure 39 | 40 | ADS7846(); 41 | 42 | void begin(void); 43 | void setOrientation(uint_least16_t o); 44 | void setRotation(uint_least16_t r); 45 | uint_least8_t setCalibration(CAL_POINT *lcd, CAL_POINT *tp); 46 | uint_least8_t writeCalibration(uint16_t eeprom_addr); 47 | uint_least8_t readCalibration(uint16_t eeprom_addr); 48 | //uint_least8_t doCalibration(MI0283QT2 *lcd, uint16_t eeprom_addr, uint_least8_t check_eeprom); //example touch panel calibration routine 49 | //uint_least8_t doCalibration(MI0283QT9 *lcd, uint16_t eeprom_addr, uint_least8_t check_eeprom); //example touch panel calibration routine 50 | void calibrate(void); 51 | uint_least16_t getX(void); 52 | uint_least16_t getY(void); 53 | uint_least16_t getXraw(void); 54 | uint_least16_t getYraw(void); 55 | uint_least8_t getPressure(void); 56 | void service(void); 57 | 58 | private: 59 | void rd_data(void); 60 | uint_least8_t rd_spi(void); 61 | void wr_spi(uint_least8_t data); 62 | }; 63 | 64 | 65 | #endif //ADS7846_h 66 | -------------------------------------------------------------------------------- /ADS7846/examples/Example/Example.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ADS7846 Touch-Controller Example 3 | */ 4 | 5 | #include 6 | #include 7 | //#include 8 | //#include 9 | //#include 10 | #include 11 | 12 | 13 | ADS7846 ads; 14 | 15 | 16 | void setup() 17 | { 18 | //init Serial port 19 | Serial.begin(9600); 20 | while(!Serial); //wait for serial port to connect - needed for Leonardo only 21 | 22 | //init Touch-Controller 23 | Serial.println("Init..."); 24 | ads.begin(); 25 | } 26 | 27 | 28 | void loop() 29 | { 30 | ads.service(); 31 | 32 | uint16_t x = ads.getXraw(); 33 | uint16_t y = ads.getYraw(); 34 | uint16_t z = ads.getPressure(); 35 | if(z) 36 | { 37 | Serial.println(x, DEC); 38 | Serial.println(y, DEC); 39 | Serial.println(z, DEC); 40 | } 41 | 42 | delay(100); 43 | } 44 | -------------------------------------------------------------------------------- /ADS7846/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ADS7846", 3 | "version": "1.0.0", 4 | "keywords": "spi, touch", 5 | "description": "ADS7846/TSC2046 Touch-Controller", 6 | "include": "ADS7846", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "dependencies": 13 | { 14 | "name": "digitalWriteFast", 15 | "frameworks": "arduino" 16 | }, 17 | "frameworks": "arduino", 18 | "platforms": "atmelavr" 19 | } 20 | -------------------------------------------------------------------------------- /ADS7846/library.properties: -------------------------------------------------------------------------------- 1 | name=ADS7846 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=ADS7846/TSC2046 Touch-Controller 6 | paragraph=ADS7846/TSC2046 Touch-Controller 7 | category=Display 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /DAC8760/DAC8760.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | DAC8760 DAC Lib for Arduino 3 | by Watterott electronic (www.watterott.com) 4 | */ 5 | 6 | #include 7 | #if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) 8 | # include 9 | #endif 10 | #if ARDUINO >= 100 11 | #include "Arduino.h" 12 | #else 13 | #include "WProgram.h" 14 | #endif 15 | #include "SPI.h" 16 | #include "digitalWriteFast.h" 17 | #include "DAC8760.h" 18 | 19 | 20 | //#define SOFTWARE_SPI //use software SPI on pins MOSI:11, MISO:12, SCK:13 21 | 22 | #if defined(SOFTWARE_SPI) 23 | # define LATCH_PIN 10 //SPI_SW_SS_PIN 24 | # define MOSI_PIN SPI_SW_MOSI_PIN 25 | # define MISO_PIN SPI_SW_MISO_PIN 26 | # define SCK_PIN SPI_SW_SCK_PIN 27 | #else 28 | # define LATCH_PIN 10 //SPI_HW_SS_PIN 29 | # define MOSI_PIN SPI_HW_MOSI_PIN 30 | # define MISO_PIN SPI_HW_MISO_PIN 31 | # define SCK_PIN SPI_HW_SCK_PIN 32 | #endif 33 | 34 | #define LATCH_HIGH() digitalWriteFast(LATCH_PIN, HIGH) 35 | #define LATCH_LOW() digitalWriteFast(LATCH_PIN, LOW) 36 | 37 | #define MOSI_HIGH() digitalWriteFast(MOSI_PIN, HIGH) 38 | #define MOSI_LOW() digitalWriteFast(MOSI_PIN, LOW) 39 | 40 | #define MISO_READ() digitalReadFast(MISO_PIN) 41 | 42 | #define SCK_HIGH() digitalWriteFast(SCK_PIN, HIGH) 43 | #define SCK_LOW() digitalWriteFast(SCK_PIN, LOW) 44 | 45 | 46 | //Address Byte 47 | #define ADDR_NOP 0x00 //No operation (NOP) 48 | #define ADDR_DATA 0x01 //Write DAC data register 49 | #define ADDR_READ 0x02 //Register read 50 | #define ADDR_CTRL 0x55 //Write control register 51 | #define ADDR_RESET 0x56 //Write reset register 52 | #define ADDR_CONFIG 0x57 //Write configuration register 53 | #define ADDR_GAIN 0x58 //Write DAC gain calibration register 54 | #define ADDR_ZERO 0x59 //Write DAC zero calibration register 55 | #define ADDR_WDT 0x95 //Watchdog timer reset 56 | 57 | //CTRL Bits 58 | #define CTRL_CLRSEL 15 //VOUT clear value: 0 = VOUT is 0V, 1 = VOUT is midscale in unipolar output and negative-full-scale in bipolar output 59 | #define CTRL_OVR 14 //Setting the bit increases the voltage output range by 10%. 60 | #define CTRL_REXT 13 //External current setting resistor enable. 61 | #define CTRL_OUTEN 12 //0 = output is disabled, 1 = output is determined by RANGE bits 62 | #define CTRL_SRCLK 8 //Slew rate clock control. Ignored when bit SREN = 0 63 | #define CTRL_SRSTEP 5 //Slew rate step size control. Ignored when bit SREN = 0 64 | #define CTRL_SREN 4 //Slew Rate Enable. 65 | #define CTRL_DCEN 3 //Daisy-chain enable. 66 | #define CTRL_RANGE 0 //Output range bits. 67 | 68 | 69 | //-------------------- Constructor -------------------- 70 | 71 | 72 | DAC8760::DAC8760(void) 73 | { 74 | return; 75 | } 76 | 77 | 78 | //-------------------- Public -------------------- 79 | 80 | 81 | void DAC8760::begin(void) 82 | { 83 | uint_least8_t r; 84 | 85 | //init pins 86 | pinMode(LATCH_PIN, OUTPUT); 87 | LATCH_LOW(); 88 | pinMode(SCK_PIN, OUTPUT); 89 | pinMode(MOSI_PIN, OUTPUT); 90 | pinMode(MISO_PIN, INPUT); 91 | //digitalWrite(MISO_PIN, HIGH); //pull-up 92 | 93 | //init SPI 94 | #if !defined(SOFTWARE_SPI) 95 | SPI.begin(); 96 | SPI.setClockDivider(SPI_CLOCK_DIV4); //SPI_CLOCK_DIV4 97 | SPI.setDataMode(SPI_MODE0); //SPI_MODE0 98 | //SPI.setBitOrder(MSBFIRST); 99 | #endif 100 | 101 | wr_reg(ADDR_RESET, 0x01); //software reset 102 | wr_reg(ADDR_DATA, 0x0000); //set data to 0 103 | wr_reg(ADDR_CTRL, (0x01<>8); 137 | wr_spi(data>>0); 138 | 139 | LATCH_HIGH(); 140 | LATCH_LOW(); 141 | /* 142 | //restore SPI settings 143 | #if !defined(SOFTWARE_SPI) && defined(__AVR__) 144 | SPCR = spcr; 145 | SPSR = spsr; 146 | #endif 147 | */ 148 | return; 149 | } 150 | 151 | 152 | void DAC8760::wr_spi(uint_least8_t data) 153 | { 154 | #if defined(SOFTWARE_SPI) 155 | for(uint_least8_t mask=0x80; mask!=0; mask>>=1) 156 | { 157 | SCK_LOW(); 158 | if(mask & data) 159 | { 160 | MOSI_HIGH(); 161 | } 162 | else 163 | { 164 | MOSI_LOW(); 165 | } 166 | SCK_HIGH(); 167 | } 168 | SCK_LOW(); 169 | #else 170 | SPI.transfer(data); 171 | #endif 172 | return; 173 | } 174 | -------------------------------------------------------------------------------- /DAC8760/DAC8760.h: -------------------------------------------------------------------------------- 1 | #ifndef DAC8760_h 2 | #define DAC8760_h 3 | 4 | 5 | #include 6 | 7 | 8 | class DAC8760 9 | { 10 | public: 11 | DAC8760(); 12 | void begin(void); 13 | void write(uint_least16_t val); 14 | 15 | private: 16 | void wr_reg(uint_least8_t reg, uint_least16_t data); 17 | void wr_spi(uint_least8_t data); 18 | }; 19 | 20 | 21 | #endif //DAC8760_h 22 | -------------------------------------------------------------------------------- /DAC8760/examples/Example/Example.ino: -------------------------------------------------------------------------------- 1 | /* 2 | DAC8760 DAC Example 3 | 4 | CLR - connected to GND 5 | LATCH - D10 6 | DIN - D11/MOSI 7 | SDO - D12/MISO 8 | SCLK - D13/CLK 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | DAC8760 dac; 17 | 18 | 19 | void setup() 20 | { 21 | //init Serial port 22 | Serial.begin(9600); 23 | while(!Serial); //wait for serial port to connect - needed for Leonardo only 24 | 25 | //init DAC 26 | Serial.println("Init DAC..."); 27 | dac.begin(); 28 | 29 | dac.write(0); //0 32767 65535 30 | } 31 | 32 | 33 | void loop() 34 | { 35 | //do nothing 36 | } 37 | -------------------------------------------------------------------------------- /DAC8760/examples/Freq2Volt/Freq2Volt.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Frequency to Voltage Converter 3 | 4 | Frequency-Input - D8/PB0/ICP1 5 | 6 | DAC8760 7 | CLR - connected to GND 8 | LATCH - D10 9 | DIN - D11/MOSI 10 | SDO - D12/MISO 11 | SCLK - D13/CLK 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | //#define DEBUG //enable serial debug output (9600 baud) 21 | 22 | #define INPUT_PIN 8 //D8/PB0/ICP1 (frequency input pin) 23 | 24 | //F_CPU = 16000000 Hz = 62.5ns 25 | //t = 800.....16000 (*62.5ns) 26 | //f = 20kHz...1kHz (f = 1/((1/F_CPU)*t)) 27 | //v = 10V.....0V 28 | //n = 65535...0 29 | #define F_MIN 1000 // 1000Hz, 250...100000Hz (min. frequency -> 0V) 30 | #define F_MAX 20000 //20000Hz, 250...100000Hz (max. frequency -> 10V) 31 | #define N_MIN 0 // 0V = 0 32 | #define N_MAX 65535 //10V = 65535 33 | 34 | 35 | DAC8760 dac; 36 | 37 | volatile uint_least16_t t_avg=0; 38 | uint_least8_t t_over=0; 39 | 40 | 41 | ISR(TIMER1_OVF_vect) //overflow after about 4ms 42 | { 43 | t_over = 1; 44 | t_avg = F_CPU/F_MIN; //set to min. freq. 45 | } 46 | 47 | 48 | ISR(TIMER1_CAPT_vect) //input capture irq 49 | { 50 | uint_least16_t t; 51 | static uint_least16_t t_last=0; 52 | 53 | TCNT1 = 0x0000; //reset timer 54 | t = ICR1; //get input capture value 55 | 56 | if(t_over) //overflow? 57 | { 58 | t_over = 0; 59 | t_last = 0; 60 | } 61 | else 62 | { 63 | //choose only on calculation method 64 | 65 | //1 - set avg to t 66 | t_avg = t; 67 | 68 | //2 - make avg from last and current 69 | // t_avg = t_last + t; 70 | // t_avg >>= 1; //div by 2 71 | 72 | //3 - make avg from all and current 73 | // t_avg += t; 74 | // t_avg >>= 1; //div by 2 75 | 76 | t_last = t; 77 | } 78 | } 79 | 80 | 81 | void print(char *s) 82 | { 83 | #ifdef DEBUG 84 | while(*s) 85 | { 86 | loop_until_bit_is_set(UCSR0A, UDRE0); 87 | UDR0 = *s++; 88 | } 89 | #endif 90 | } 91 | 92 | 93 | void print(uint_least16_t i) 94 | { 95 | #ifdef DEBUG 96 | char tmp[8]; 97 | 98 | sprintf(tmp, "%u", i); 99 | print(tmp); 100 | #endif 101 | } 102 | 103 | 104 | void setup() 105 | { 106 | //init Serial port 107 | #ifdef DEBUG 108 | Serial.begin(9600); 109 | while(!Serial); //wait for serial port to connect - needed for Leonardo only 110 | #endif 111 | 112 | //init Pins 113 | print("Init Pins...\n"); 114 | pinMode(INPUT_PIN, INPUT); 115 | digitalWrite(INPUT_PIN, HIGH); //pull-up 116 | 117 | //init DAC 118 | print("Init DAC...\n"); 119 | dac.begin(); 120 | dac.write(0); 121 | 122 | //disable Arduino interrupts and init timer 123 | print("Init IRQs...\n"); 124 | cli(); //disable all interrupts 125 | //disable UART interrupts 126 | UCSR0B &= ~((1< F_MAX){ f = F_MAX; } //freq. to high? 168 | n = map(f, F_MIN, F_MAX, N_MIN, N_MAX); //map freq. to voltage 169 | 170 | if(n != n_last) //n changed? 171 | { 172 | n_last = n; 173 | 174 | //set DAC output 175 | dac.write(n); //set DAC output 176 | 177 | #ifdef DEBUG 178 | //print("t:"); 179 | //print(t); 180 | print(" f:"); 181 | print(f); 182 | //print(" n:"); 183 | //print(n); 184 | print(" mV:"); 185 | n = map(n, 0, 65535, 0, 10000); //map n to voltage 186 | print(n); 187 | print("\n"); 188 | #endif 189 | } 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /DAC8760/examples/Freq2VoltAdv/Freq2VoltAdv.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Frequency to Voltage Converter with forward/backward output 3 | 4 | F-Input - D8/PB0/ICP1 //frequency 5 | DIR-Input - D2 //direction 6 | F-Output - D3 //forward 7 | B-Output - D4 //backward 8 | 9 | DAC8760 10 | CLR - connected to GND 11 | LATCH - D10 12 | DIN - D11/MOSI 13 | SDO - D12/MISO 14 | SCLK - D13/CLK 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | 24 | //#define DEBUG //enable serial debug output (9600 baud) 25 | 26 | #define INPUT_PIN 8 //D8/PB0/ICP1 (frequency input pin) 27 | #define DIR_PIN 2 //D2 (direction input pin) 28 | #define F_PIN 3 //D3 (forward output pin) 29 | #define B_PIN 4 //D4 (backward output pin) 30 | 31 | #define DIR_READ()digitalReadFast(DIR_PIN) 32 | #define F_ON() digitalWriteFast(F_PIN, HIGH) 33 | #define F_OFF() digitalWriteFast(F_PIN, LOW) 34 | #define B_ON() digitalWriteFast(B_PIN, HIGH) 35 | #define B_OFF() digitalWriteFast(B_PIN, LOW) 36 | 37 | //F_CPU = 16000000 Hz = 62.5ns 38 | //t = 800.....16000 (*62.5ns) 39 | //f = 20kHz...1kHz (f = 1/((1/F_CPU)*t)) 40 | //v = 10V.....0V 41 | //n = 65535...0 42 | #define F_MIN 1000 // 1000Hz, 250...100000Hz (min. frequency -> 0V) 43 | #define F_MAX 20000 //20000Hz, 250...100000Hz (max. frequency -> 10V) 44 | #define N_MIN 0 // 0V = 0 45 | #define N_MAX 65535 //10V = 65535 46 | 47 | 48 | DAC8760 dac; 49 | 50 | volatile uint_least16_t t_avg=0; 51 | uint_least8_t t_over=0; 52 | 53 | 54 | ISR(TIMER1_OVF_vect) //overflow irq after about 4ms 55 | { 56 | if(t_over) //2*4ms=8ms 57 | { 58 | F_OFF(); 59 | B_OFF(); 60 | } 61 | t_over = 1; 62 | t_avg = F_CPU/F_MIN; //set to min. freq. 63 | } 64 | 65 | 66 | ISR(TIMER1_CAPT_vect) //input capture irq 67 | { 68 | uint_least16_t t; 69 | static uint_least16_t t_last=0; 70 | 71 | TCNT1 = 0x0000; //reset timer 72 | t = ICR1; //get input capture value 73 | 74 | if(t_over) //overflow? 75 | { 76 | t_over = 0; 77 | t_last = 0; 78 | } 79 | else 80 | { 81 | //choose only on calculation method 82 | 83 | //1 - set avg to t 84 | t_avg = t; 85 | 86 | //2 - make avg from last and current 87 | // t_avg = t_last + t; 88 | // t_avg >>= 1; //div by 2 89 | 90 | //3 - make avg from all and current 91 | // t_avg += t; 92 | // t_avg >>= 1; //div by 2 93 | 94 | t_last = t; 95 | } 96 | } 97 | 98 | 99 | void print(char *s) 100 | { 101 | #ifdef DEBUG 102 | while(*s) 103 | { 104 | loop_until_bit_is_set(UCSR0A, UDRE0); 105 | UDR0 = *s++; 106 | } 107 | #endif 108 | } 109 | 110 | 111 | void print(uint_least16_t i) 112 | { 113 | #ifdef DEBUG 114 | char tmp[8]; 115 | 116 | sprintf(tmp, "%u", i); 117 | print(tmp); 118 | #endif 119 | } 120 | 121 | 122 | void setup() 123 | { 124 | //init Serial port 125 | #ifdef DEBUG 126 | Serial.begin(9600); 127 | while(!Serial); //wait for serial port to connect - needed for Leonardo only 128 | #endif 129 | 130 | //init Pins 131 | print("Init Pins...\n"); 132 | pinMode(INPUT_PIN, INPUT); 133 | digitalWrite(INPUT_PIN, HIGH); //pull-up 134 | pinMode(DIR_PIN, INPUT); 135 | digitalWrite(DIR_PIN, HIGH); //pull-up 136 | pinMode(F_PIN, OUTPUT); 137 | pinMode(B_PIN, OUTPUT); 138 | F_OFF(); 139 | B_OFF(); 140 | 141 | //init DAC 142 | print("Init DAC...\n"); 143 | dac.begin(); 144 | dac.write(0); 145 | 146 | //disable Arduino interrupts and init timer 147 | print("Init IRQs...\n"); 148 | cli(); //disable all interrupts 149 | //disable UART interrupts 150 | UCSR0B &= ~((1< F_MAX){ f = F_MAX; } //freq. to high? 199 | n = map(f, F_MIN, F_MAX, N_MIN, N_MAX); //map freq. to n (voltage) 200 | 201 | if(n != n_last) //n changed? 202 | { 203 | n_last = n; 204 | 205 | //set DAC output 206 | dac.write(n); 207 | 208 | //set digital outputs 209 | if(n) 210 | { 211 | if(DIR_READ()) 212 | { 213 | F_ON(); 214 | B_OFF(); 215 | } 216 | else 217 | { 218 | F_OFF(); 219 | B_ON(); 220 | } 221 | } 222 | else 223 | { 224 | F_OFF(); 225 | B_OFF(); 226 | } 227 | 228 | #ifdef DEBUG 229 | //print("t:"); 230 | //print(t); 231 | print(" f:"); 232 | print(f); 233 | //print(" n:"); 234 | //print(n); 235 | print(" mV:"); 236 | n = map(n, 0, 65535, 0, 10000); //map n to voltage 237 | print(n); 238 | print("\n"); 239 | #endif 240 | } 241 | } 242 | } 243 | -------------------------------------------------------------------------------- /DAC8760/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DAC8760", 3 | "version": "1.0.0", 4 | "keywords": "spi, dac, analog, output, converter, signal", 5 | "description": "DAC8760 DAC (Digital-Analog-Converter)", 6 | "include": "DAC8760", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "dependencies": 13 | { 14 | "name": "digitalWriteFast", 15 | "frameworks": "arduino" 16 | }, 17 | "frameworks": "arduino", 18 | "platforms": "atmelavr" 19 | } 20 | -------------------------------------------------------------------------------- /DAC8760/library.properties: -------------------------------------------------------------------------------- 1 | name=DAC8760 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=DAC8760 DAC (Digital-Analog-Converter) 6 | paragraph=DAC8760 DAC (Digital-Analog-Converter) 7 | category=Signal Input/Output 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /DS1307/DS1307.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | DS1307 RTC Lib for Arduino 3 | by Watterott electronic (www.watterott.com) 4 | */ 5 | 6 | #include 7 | #if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) 8 | # include 9 | #endif 10 | #if ARDUINO >= 100 11 | # include "Arduino.h" 12 | #else 13 | # include "WProgram.h" 14 | #endif 15 | #include "Wire.h" 16 | #include "DS1307.h" 17 | 18 | 19 | #define I2C_ADDR 0x68 20 | 21 | 22 | //-------------------- Constructor -------------------- 23 | 24 | 25 | DS1307::DS1307(void) 26 | { 27 | return; 28 | } 29 | 30 | 31 | //-------------------- Public -------------------- 32 | 33 | 34 | void DS1307::begin(void) 35 | { 36 | Wire.begin(); //init I2C lib 37 | } 38 | 39 | 40 | void DS1307::start(void) 41 | { 42 | uint8_t sec; 43 | 44 | //get second and CH bit 45 | Wire.beginTransmission(I2C_ADDR); 46 | Wire.write(byte(0x00)); 47 | Wire.endTransmission(); 48 | Wire.requestFrom(I2C_ADDR, 1); 49 | sec = Wire.read(); 50 | Wire.read(); 51 | 52 | //set second and clear CH bit 53 | Wire.beginTransmission(I2C_ADDR); 54 | Wire.write(byte(0x00)); 55 | Wire.write(sec & 0x7F); 56 | Wire.endTransmission(); 57 | 58 | return; 59 | } 60 | 61 | 62 | void DS1307::stop(void) 63 | { 64 | uint8_t sec, d; 65 | 66 | //get second and CH bit 67 | Wire.beginTransmission(I2C_ADDR); 68 | Wire.write(byte(0x00)); 69 | Wire.endTransmission(); 70 | Wire.requestFrom(I2C_ADDR, 1); 71 | sec = Wire.read(); 72 | d = Wire.read(); 73 | 74 | //set second and CH bit 75 | Wire.beginTransmission(I2C_ADDR); 76 | Wire.write(byte(0x00)); 77 | Wire.write(sec | 0x80); //hold 78 | Wire.endTransmission(); 79 | 80 | return; 81 | } 82 | 83 | 84 | void DS1307::get(uint8_t *sec, uint8_t *min, uint8_t *hour, uint8_t *day, uint8_t *month, uint16_t *year) 85 | { 86 | Wire.beginTransmission(I2C_ADDR); 87 | Wire.write(byte(0x00)); 88 | Wire.endTransmission(); 89 | 90 | Wire.requestFrom(I2C_ADDR, 7); 91 | *sec = bcd2bin(Wire.read() & 0x7F); 92 | *min = bcd2bin(Wire.read()); 93 | *hour = bcd2bin(Wire.read()); 94 | bcd2bin(Wire.read()); //day of week 95 | *day = bcd2bin(Wire.read()); 96 | *month = bcd2bin(Wire.read()); 97 | *year = bcd2bin(Wire.read()) + 2000; 98 | 99 | return; 100 | } 101 | 102 | 103 | void DS1307::get(int *sec, int *min, int *hour, int *day, int *month, int *year) 104 | { 105 | Wire.beginTransmission(I2C_ADDR); 106 | Wire.write(byte(0x00)); 107 | Wire.endTransmission(); 108 | 109 | Wire.requestFrom(I2C_ADDR, 7); 110 | *sec = bcd2bin(Wire.read() & 0x7F); 111 | *min = bcd2bin(Wire.read()); 112 | *hour = bcd2bin(Wire.read()); 113 | bcd2bin(Wire.read()); //day of week 114 | *day = bcd2bin(Wire.read()); 115 | *month = bcd2bin(Wire.read()); 116 | *year = bcd2bin(Wire.read()) + 2000; 117 | 118 | return; 119 | } 120 | 121 | 122 | void DS1307::set(uint8_t sec, uint8_t min, uint8_t hour, uint8_t day, uint8_t month, uint16_t year) 123 | { 124 | uint8_t ch, d; 125 | 126 | if(year >= 2000) 127 | { 128 | year -= 2000; 129 | } 130 | 131 | //get CH bit 132 | Wire.beginTransmission(I2C_ADDR); 133 | Wire.write(byte(0x00)); 134 | Wire.endTransmission(); 135 | Wire.requestFrom(I2C_ADDR, 1); 136 | ch = Wire.read(); 137 | d = Wire.read(); 138 | 139 | if(ch & 0x80) //CH set? 140 | { 141 | ch = 0x80; 142 | } 143 | else 144 | { 145 | ch = 0x00; 146 | } 147 | 148 | //set time and date 149 | Wire.beginTransmission(I2C_ADDR); 150 | Wire.write(byte(0x00)); 151 | Wire.write(bin2bcd(sec) | ch); 152 | Wire.write(bin2bcd(min)); 153 | Wire.write(bin2bcd(hour)); 154 | Wire.write(bin2bcd(0)); 155 | Wire.write(bin2bcd(day)); 156 | Wire.write(bin2bcd(month)); 157 | Wire.write(bin2bcd(year)); 158 | Wire.endTransmission(); 159 | 160 | return; 161 | } 162 | 163 | 164 | void DS1307::set(int sec, int min, int hour, int day, int month, int year) 165 | { 166 | return set((uint8_t)sec, (uint8_t)min, (uint8_t)hour, (uint8_t)day, (uint8_t)month, (uint16_t)year); 167 | } 168 | 169 | 170 | //-------------------- Private -------------------- 171 | 172 | 173 | uint8_t DS1307::bin2bcd(uint8_t val) 174 | { 175 | return val + 6 * (val / 10); 176 | } 177 | 178 | 179 | uint8_t DS1307::bcd2bin(uint8_t val) 180 | { 181 | return val - 6 * (val >> 4); 182 | } 183 | -------------------------------------------------------------------------------- /DS1307/DS1307.h: -------------------------------------------------------------------------------- 1 | #ifndef DS1307_h 2 | #define DS1307_h 3 | 4 | 5 | #include 6 | 7 | 8 | class DS1307 9 | { 10 | public: 11 | DS1307(); 12 | 13 | void begin(void); 14 | void start(void); 15 | void stop(void); 16 | void get(uint8_t *sec, uint8_t *min, uint8_t *hour, uint8_t *day, uint8_t *month, uint16_t *year); 17 | void get(int *sec, int *min, int *hour, int *day, int *month, int *year); 18 | void set(uint8_t sec, uint8_t min, uint8_t hour, uint8_t day, uint8_t month, uint16_t year); 19 | void set(int sec, int min, int hour, int day, int month, int year); 20 | 21 | private: 22 | uint8_t bin2bcd(uint8_t val); 23 | uint8_t bcd2bin(uint8_t val); 24 | }; 25 | 26 | 27 | #endif //DS1307_h 28 | -------------------------------------------------------------------------------- /DS1307/examples/Example/Example.ino: -------------------------------------------------------------------------------- 1 | /* 2 | DS1307 RTC (Real-Time-Clock) Example 3 | 4 | Uno A4 (SDA), A5 (SCL) 5 | Mega 20 (SDA), 21 (SCL) 6 | Leonardo 2 (SDA), 3 (SCL) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | 13 | DS1307 rtc; 14 | 15 | 16 | void setup() 17 | { 18 | //init Serial port 19 | Serial.begin(9600); 20 | while(!Serial); //wait for serial port to connect - needed for Leonardo only 21 | 22 | //init RTC 23 | Serial.println("Init RTC..."); 24 | rtc.begin(); 25 | 26 | //only set the date+time one time 27 | // rtc.set(0, 0, 8, 24, 12, 2014); //08:00:00 24.12.2014 //sec, min, hour, day, month, year 28 | 29 | //stop/pause RTC 30 | // rtc.stop(); 31 | 32 | //start RTC 33 | rtc.start(); 34 | } 35 | 36 | 37 | void loop() 38 | { 39 | uint8_t sec, min, hour, day, month; 40 | uint16_t year; 41 | 42 | //get time from RTC 43 | rtc.get(&sec, &min, &hour, &day, &month, &year); 44 | 45 | //serial output 46 | Serial.print("\nTime: "); 47 | Serial.print(hour, DEC); 48 | Serial.print(":"); 49 | Serial.print(min, DEC); 50 | Serial.print(":"); 51 | Serial.print(sec, DEC); 52 | 53 | Serial.print("\nDate: "); 54 | Serial.print(day, DEC); 55 | Serial.print("."); 56 | Serial.print(month, DEC); 57 | Serial.print("."); 58 | Serial.print(year, DEC); 59 | 60 | //wait a second 61 | delay(1000); 62 | } 63 | -------------------------------------------------------------------------------- /DS1307/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DS1307", 3 | "version": "1.0.0", 4 | "keywords": "i2c, rtc, time, clock", 5 | "description": "DS1307 RTC (Real-Time-Clock)", 6 | "include": "DS1307", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "frameworks": "arduino", 13 | "platforms": "atmelavr" 14 | } 15 | -------------------------------------------------------------------------------- /DS1307/library.properties: -------------------------------------------------------------------------------- 1 | name=DS1307 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=DS1307 RTC (Real-Time-Clock) 6 | paragraph=DS1307 RTC (Real-Time-Clock) 7 | category=Timing 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /DisplayI2C/DisplayI2C.h: -------------------------------------------------------------------------------- 1 | #ifndef DisplayI2C_h 2 | #define DisplayI2C_h 3 | 4 | 5 | #include 6 | #if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) 7 | # include 8 | #endif 9 | #include "GraphicsLib.h" 10 | 11 | 12 | class DisplayI2C : public GraphicsLib 13 | { 14 | public: 15 | DisplayI2C(); 16 | 17 | void begin(uint_least8_t addr, uint_least8_t rst_pin); 18 | void begin(uint_least8_t addr); 19 | void begin(void); 20 | uint_least8_t getSize(void); 21 | uint_least8_t getVersion(char *v); 22 | uint_least8_t getFeatures(void); 23 | void setFeatures(uint_least8_t f); 24 | void led(uint_least8_t power); 25 | void invertDisplay(uint_least8_t invert); 26 | void setOrientation(uint_least16_t o); 27 | void setArea(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1); 28 | void drawStart(void); 29 | void draw(uint_least16_t color); 30 | void drawStop(void); 31 | void fillScreen(uint_least16_t color); 32 | void drawPixel(int_least16_t x0, int_least16_t y0, uint_least16_t color); 33 | void drawLine(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1, uint_least16_t color); 34 | void drawRect(int_least16_t x0, int_least16_t y0, int_least16_t w, int_least16_t h, uint_least16_t color); 35 | void fillRect(int_least16_t x0, int_least16_t y0, int_least16_t w, int_least16_t h, uint_least16_t color); 36 | void drawTriangle(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1, int_least16_t x2, int_least16_t y2, uint_least16_t color); 37 | void fillTriangle(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1, int_least16_t x2, int_least16_t y2, uint_least16_t color); 38 | void drawRoundRect(int_least16_t x0, int_least16_t y0, int_least16_t w, int_least16_t h, int_least16_t r, uint_least16_t color); 39 | void fillRoundRect(int_least16_t x0, int_least16_t y0, int_least16_t w, int_least16_t h, int_least16_t r, uint_least16_t color); 40 | void drawCircle(int_least16_t x0, int_least16_t y0, int_least16_t r, uint_least16_t color); 41 | void fillCircle(int_least16_t x0, int_least16_t y0, int_least16_t r, uint_least16_t color); 42 | void drawEllipse(int_least16_t x0, int_least16_t y0, int_least16_t r_x, int_least16_t r_y, uint_least16_t color); 43 | void fillEllipse(int_least16_t x0, int_least16_t y0, int_least16_t r_x, int_least16_t r_y, uint_least16_t color); 44 | int_least16_t drawChar(int_least16_t x, int_least16_t y, char c, uint_least16_t color, uint_least16_t bg, uint_least8_t size); 45 | int_least16_t drawChar(int_least16_t x, int_least16_t y, unsigned char c, uint_least16_t color, uint_least16_t bg, uint_least8_t size); 46 | int_least16_t drawText(int_least16_t x, int_least16_t y, const char *s, uint_least16_t color, uint_least16_t bg, uint_least8_t size); 47 | int_least16_t drawText(int_least16_t x, int_least16_t y, String &s, uint_least16_t color, uint_least16_t bg, uint_least8_t size); 48 | #if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) 49 | int_least16_t drawTextPGM(int_least16_t x, int_least16_t y, PGM_P s, uint_least16_t color, uint_least16_t bg, uint_least8_t size); 50 | #endif 51 | 52 | //touch panel funcions 53 | uint_least8_t touchRead(void); 54 | void touchStartCal(void); 55 | int_least16_t touchX(void); 56 | int_least16_t touchY(void); 57 | int_least16_t touchZ(void); 58 | 59 | private: 60 | uint_least8_t bigger_8bit, features; 61 | int_least16_t display_width, display_height; 62 | int i2c_addr; 63 | }; 64 | 65 | 66 | #endif //DisplayI2C_h 67 | -------------------------------------------------------------------------------- /DisplayI2C/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DisplayI2C", 3 | "version": "1.0.0", 4 | "keywords": "i2c, graphics, display, lcd", 5 | "description": "MI0283QT-Adapter v2 + GLCD-Shield (I2C)", 6 | "include": "DisplayI2C", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "dependencies": 13 | [ 14 | { 15 | "name": "digitalWriteFast", 16 | "frameworks": "arduino" 17 | }, 18 | { 19 | "name": "GraphicsLib", 20 | "frameworks": "arduino" 21 | } 22 | ], 23 | "frameworks": "arduino", 24 | "platforms": "atmelavr" 25 | } 26 | -------------------------------------------------------------------------------- /DisplayI2C/library.properties: -------------------------------------------------------------------------------- 1 | name=DisplayI2C 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=MI0283QT-Adapter v2 + GLCD-Shield (I2C) 6 | paragraph=MI0283QT-Adapter v2 + GLCD-Shield (I2C) 7 | category=Display 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /DisplaySPI/DisplaySPI.h: -------------------------------------------------------------------------------- 1 | #ifndef DisplaySPI_h 2 | #define DisplaySPI_h 3 | 4 | 5 | #include 6 | #if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) 7 | # include 8 | #endif 9 | #include "GraphicsLib.h" 10 | 11 | 12 | class DisplaySPI : public GraphicsLib 13 | { 14 | public: 15 | DisplaySPI(); 16 | 17 | void begin(uint_least8_t clock_div, uint_least8_t rst_pin); //SPI_CLOCK_DIV2 SPI_CLOCK_DIV4 SPI_CLOCK_DIV8 SPI_CLOCK_DIV16 SPI_CLOCK_DIV32 SPI_CLOCK_DIV64 SPI_CLOCK_DIV128 18 | void begin(uint_least8_t clock_div); 19 | void begin(void); 20 | uint_least8_t getSize(void); 21 | uint_least8_t getVersion(char *v); 22 | uint_least8_t getFeatures(void); 23 | void setFeatures(uint_least8_t f); 24 | void led(uint_least8_t power); 25 | void invertDisplay(uint_least8_t invert); 26 | void setOrientation(uint_least16_t o); 27 | void setArea(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1); 28 | void drawStart(void); 29 | void draw(uint_least16_t color); 30 | void drawStop(void); 31 | void fillScreen(uint_least16_t color); 32 | void drawPixel(int_least16_t x0, int_least16_t y0, uint_least16_t color); 33 | void drawLine(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1, uint_least16_t color); 34 | void drawRect(int_least16_t x0, int_least16_t y0, int_least16_t w, int_least16_t h, uint_least16_t color); 35 | void fillRect(int_least16_t x0, int_least16_t y0, int_least16_t w, int_least16_t h, uint_least16_t color); 36 | void drawTriangle(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1, int_least16_t x2, int_least16_t y2, uint_least16_t color); 37 | void fillTriangle(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1, int_least16_t x2, int_least16_t y2, uint_least16_t color); 38 | void drawRoundRect(int_least16_t x0, int_least16_t y0, int_least16_t w, int_least16_t h, int_least16_t r, uint_least16_t color); 39 | void fillRoundRect(int_least16_t x0, int_least16_t y0, int_least16_t w, int_least16_t h, int_least16_t r, uint_least16_t color); 40 | void drawCircle(int_least16_t x0, int_least16_t y0, int_least16_t r, uint_least16_t color); 41 | void fillCircle(int_least16_t x0, int_least16_t y0, int_least16_t r, uint_least16_t color); 42 | void drawEllipse(int_least16_t x0, int_least16_t y0, int_least16_t r_x, int_least16_t r_y, uint_least16_t color); 43 | void fillEllipse(int_least16_t x0, int_least16_t y0, int_least16_t r_x, int_least16_t r_y, uint_least16_t color); 44 | int_least16_t drawChar(int_least16_t x, int_least16_t y, char c, uint_least16_t color, uint_least16_t bg, uint_least8_t size); 45 | int_least16_t drawChar(int_least16_t x, int_least16_t y, unsigned char c, uint_least16_t color, uint_least16_t bg, uint_least8_t size); 46 | int_least16_t drawText(int_least16_t x, int_least16_t y, const char *s, uint_least16_t color, uint_least16_t bg, uint_least8_t size); 47 | int_least16_t drawText(int_least16_t x, int_least16_t y, String &s, uint_least16_t color, uint_least16_t bg, uint_least8_t size); 48 | #if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) 49 | int_least16_t drawTextPGM(int_least16_t x, int_least16_t y, PGM_P s, uint_least16_t color, uint_least16_t bg, uint_least8_t size); 50 | #endif 51 | 52 | //touch panel funcions 53 | uint_least8_t touchRead(void); 54 | void touchStartCal(void); 55 | int_least16_t touchX(void); 56 | int_least16_t touchY(void); 57 | int_least16_t touchZ(void); 58 | 59 | private: 60 | uint_least8_t bigger_8bit, features; 61 | int_least16_t display_width, display_height; 62 | }; 63 | 64 | 65 | #endif //DisplaySPI_h 66 | -------------------------------------------------------------------------------- /DisplaySPI/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DisplaySPI", 3 | "version": "1.0.0", 4 | "keywords": "spi, graphics, display, lcd", 5 | "description": "MI0283QT-Adapter v2 + GLCD-Shield (SPI)", 6 | "include": "DisplaySPI", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "dependencies": 13 | [ 14 | { 15 | "name": "digitalWriteFast", 16 | "frameworks": "arduino" 17 | }, 18 | { 19 | "name": "GraphicsLib", 20 | "frameworks": "arduino" 21 | } 22 | ], 23 | "frameworks": "arduino", 24 | "platforms": "atmelavr" 25 | } 26 | -------------------------------------------------------------------------------- /DisplaySPI/library.properties: -------------------------------------------------------------------------------- 1 | name=DisplaySPI 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=MI0283QT-Adapter v2 + GLCD-Shield (SPI) 6 | paragraph=MI0283QT-Adapter v2 + GLCD-Shield (SPI) 7 | category=Display 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /DisplayUART/DisplayUART.h: -------------------------------------------------------------------------------- 1 | #ifndef DisplayUART_h 2 | #define DisplayUART_h 3 | 4 | 5 | #include 6 | #if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) 7 | # include 8 | #endif 9 | #include "GraphicsLib.h" 10 | 11 | 12 | class DisplayUART : public GraphicsLib 13 | { 14 | public: 15 | DisplayUART(); 16 | 17 | void begin(uint_least8_t rx_pin, uint_least8_t tx_pin, uint_least8_t cs_pin, uint_least8_t rst_pin); 18 | void begin(uint_least8_t rx_pin, uint_least8_t tx_pin, uint_least8_t cs_pin); 19 | uint_least8_t getSize(void); 20 | uint_least8_t getVersion(char *v); 21 | uint_least8_t getFeatures(void); 22 | void setFeatures(uint_least8_t f); 23 | void led(uint_least8_t power); 24 | void invertDisplay(uint_least8_t invert); 25 | void setOrientation(uint_least16_t o); 26 | void setArea(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1); 27 | void drawStart(void); 28 | void draw(uint_least16_t color); 29 | void drawStop(void); 30 | void fillScreen(uint_least16_t color); 31 | void drawPixel(int_least16_t x0, int_least16_t y0, uint_least16_t color); 32 | void drawLine(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1, uint_least16_t color); 33 | void drawRect(int_least16_t x0, int_least16_t y0, int_least16_t w, int_least16_t h, uint_least16_t color); 34 | void fillRect(int_least16_t x0, int_least16_t y0, int_least16_t w, int_least16_t h, uint_least16_t color); 35 | void drawTriangle(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1, int_least16_t x2, int_least16_t y2, uint_least16_t color); 36 | void fillTriangle(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1, int_least16_t x2, int_least16_t y2, uint_least16_t color); 37 | void drawRoundRect(int_least16_t x0, int_least16_t y0, int_least16_t w, int_least16_t h, int_least16_t r, uint_least16_t color); 38 | void fillRoundRect(int_least16_t x0, int_least16_t y0, int_least16_t w, int_least16_t h, int_least16_t r, uint_least16_t color); 39 | void drawCircle(int_least16_t x0, int_least16_t y0, int_least16_t r, uint_least16_t color); 40 | void fillCircle(int_least16_t x0, int_least16_t y0, int_least16_t r, uint_least16_t color); 41 | void drawEllipse(int_least16_t x0, int_least16_t y0, int_least16_t r_x, int_least16_t r_y, uint_least16_t color); 42 | void fillEllipse(int_least16_t x0, int_least16_t y0, int_least16_t r_x, int_least16_t r_y, uint_least16_t color); 43 | int_least16_t drawChar(int_least16_t x, int_least16_t y, char c, uint_least16_t color, uint_least16_t bg, uint_least8_t size); 44 | int_least16_t drawChar(int_least16_t x, int_least16_t y, unsigned char c, uint_least16_t color, uint_least16_t bg, uint_least8_t size); 45 | int_least16_t drawText(int_least16_t x, int_least16_t y, const char *s, uint_least16_t color, uint_least16_t bg, uint_least8_t size); 46 | int_least16_t drawText(int_least16_t x, int_least16_t y, String &s, uint_least16_t color, uint_least16_t bg, uint_least8_t size); 47 | #if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) 48 | int_least16_t drawTextPGM(int_least16_t x, int_least16_t y, PGM_P s, uint_least16_t color, uint_least16_t bg, uint_least8_t size); 49 | #endif 50 | 51 | //touch panel funcions 52 | uint_least8_t touchRead(void); 53 | void touchStartCal(void); 54 | int_least16_t touchX(void); 55 | int_least16_t touchY(void); 56 | int_least16_t touchZ(void); 57 | 58 | private: 59 | uint_least8_t bigger_8bit, features; 60 | int_least16_t display_width, display_height; 61 | uint_least8_t pin_cs; 62 | }; 63 | 64 | 65 | #endif //DisplayUART_h 66 | -------------------------------------------------------------------------------- /DisplayUART/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DisplayUART", 3 | "version": "1.0.0", 4 | "keywords": "uart, graphics, display, lcd", 5 | "description": "MI0283QT-Adapter v2 + GLCD-Shield (UART)", 6 | "include": "DisplayUART", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "dependencies": 13 | [ 14 | { 15 | "name": "digitalWriteFast", 16 | "frameworks": "arduino" 17 | }, 18 | { 19 | "name": "GraphicsLib", 20 | "frameworks": "arduino" 21 | } 22 | ], 23 | "frameworks": "arduino", 24 | "platforms": "atmelavr" 25 | } 26 | -------------------------------------------------------------------------------- /DisplayUART/library.properties: -------------------------------------------------------------------------------- 1 | name=DisplayUART 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=MI0283QT-Adapter v2 + GLCD-Shield (UART) 6 | paragraph=MI0283QT-Adapter v2 + GLCD-Shield (UART) 7 | category=Display 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /GraphicsLib/BMPheader.h: -------------------------------------------------------------------------------- 1 | 2 | typedef struct __attribute__((packed)) 3 | { 4 | uint8_t magic[2]; 5 | uint32_t size; 6 | uint16_t rsrvd1; 7 | uint16_t rsrvd2; 8 | uint32_t offset; 9 | } BMP_Header; 10 | 11 | 12 | typedef struct __attribute__((packed)) 13 | { 14 | uint32_t size; 15 | uint32_t width; 16 | uint32_t height; 17 | uint16_t nplanes; 18 | uint16_t bitspp; 19 | uint32_t compress; 20 | uint32_t isize; 21 | uint32_t hres; 22 | uint32_t vres; 23 | uint32_t colors; 24 | uint32_t impcolors; 25 | } BMP_DIPHeader; 26 | -------------------------------------------------------------------------------- /GraphicsLib/examples/Demo/Demo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | GraphicsLib Demo 3 | 4 | This sketch demonstrates the functions of the GraphicsLib. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | //Declare only one display ! 24 | // SSD1331 lcd; 25 | // S65L2F50 lcd; 26 | // S65LPH88 lcd; 27 | // S65LS020 lcd; 28 | // MI0283QT2 lcd; //MI0283QT2 Adapter v1 29 | // MI0283QT9 lcd; //MI0283QT9 Adapter v1 30 | // DisplaySPI lcd; //SPI (GLCD-Shield or MI0283QT Adapter v2) 31 | // DisplayUART lcd; //UART (GLCD-Shield or MI0283QT Adapter v2) 32 | DisplayI2C lcd; //I2C (GLCD-Shield or MI0283QT Adapter v2) 33 | 34 | 35 | void setup() 36 | { 37 | uint8_t clear_bg=0x00; //0x80 = dont clear background for fonts (only for DisplayXXX) 38 | 39 | //init display 40 | lcd.begin(); 41 | //SPI Displays 42 | // lcd.begin(); //spi-clk=Fcpu/4 43 | // lcd.begin(SPI_CLOCK_DIV2); //spi-clk=Fcpu/2 44 | // lcd.begin(SPI_CLOCK_DIV16); //spi-clk=Fcpu/16 45 | // lcd.begin(SPI_CLOCK_DIV4, 8); //spi-clk=Fcpu/4, rst-pin=8 46 | //UART Displays 47 | // lcd.begin(5, 6, 7); //rx-pin=5, tx-pin=6, cs-pin=7 48 | // lcd.begin(5, 6, 7, 8); //rx-pin=5, tx-pin=6, cs-pin=7, rst-pin=8 49 | //I2C Displays 50 | // lcd.begin(0x20); //addr=0x20 51 | // lcd.begin(0x20, 8); //addr=0x20, rst-pin=8 52 | 53 | 54 | //clear screen 55 | lcd.fillScreen(RGB(255,255,255)); 56 | 57 | 58 | //setOrientation 59 | lcd.setOrientation(0); 60 | lcd.drawText(10, 10, "test 1", RGB(0,0,0), RGB(255,255,255), 1); 61 | lcd.setOrientation(90); 62 | lcd.drawText(10, 10, "test 2", RGB(0,0,0), RGB(255,255,255), 1); 63 | lcd.setOrientation(180); 64 | lcd.drawText(10, 10, "test 3", RGB(0,0,0), RGB(255,255,255), 1); 65 | lcd.setOrientation(270); 66 | lcd.drawText(10, 10, "test 4", RGB(0,0,0), RGB(255,255,255), 1); 67 | lcd.setOrientation(0); 68 | 69 | 70 | //drawPixel, drawLine, drawRect, fillRect, drawTriangle, fillTriangle, drawRoundRect, fillRoundRect, drawCircle, fillCircle, drawEllipse, fillEllipse 71 | lcd.fillEllipse(20,30,10,15,RGB(200, 0, 0)); 72 | lcd.drawEllipse(20,30,10,15,RGB( 0, 0, 0)); 73 | 74 | lcd.fillCircle(50,30,10,RGB( 0,200, 0)); 75 | lcd.drawCircle(50,30,12,RGB( 0, 0, 0)); 76 | 77 | lcd.fillRoundRect(71,21,18,18,5,RGB( 0, 0,200)); 78 | lcd.drawRoundRect(70,20,20,20,5,RGB( 0, 0, 0)); 79 | 80 | lcd.fillTriangle(30,50,10,90,50,80,RGB( 0,200,200)); 81 | lcd.drawTriangle(30,50,10,90,50,80,RGB( 0, 0, 0)); 82 | 83 | lcd.fillRect(50,50,20,20,RGB(200,200, 0)); 84 | lcd.drawRect(51,51,18,18,RGB( 0, 0, 0)); 85 | 86 | lcd.drawLine(10,10,50,60,RGB( 10, 10, 10)); 87 | lcd.drawLine(10,60,50,10,RGB( 10, 10, 10)); 88 | 89 | lcd.drawPixel(5,5,RGB(100,100,100)); 90 | 91 | 92 | //drawText 93 | lcd.drawTextPGM(50, 10, PSTR("String from Flash"), RGB(0,0,0), RGB(255,255,255), 1|clear_bg); //string from flash (only AVR) 94 | lcd.drawText(50, 20, "String from RAM", RGB(0,0,0), RGB(255,255,255), 1|clear_bg); //string from ram 95 | 96 | 97 | //drawInteger 98 | lcd.drawInteger(5, 20, 1234, DEC, RGB(0,0,0), RGB(255,255,255), 1|clear_bg); //dec 99 | lcd.drawInteger(5, 30, 1234, HEX, RGB(0,0,0), RGB(255,255,255), 1|clear_bg); //hex 100 | lcd.drawInteger(5, 40, 1234, OCT, RGB(0,0,0), RGB(255,255,255), 1|clear_bg); //oct 101 | lcd.drawInteger(5, 50, 1234, BIN, RGB(0,0,0), RGB(255,255,255), 1|clear_bg); //bin 102 | 103 | 104 | //print 105 | lcd.setTextSize(1|clear_bg); 106 | lcd.setTextColor(RGB(200,0,0), RGB(255,255,255)); 107 | lcd.setCursor(2, 60); 108 | lcd.print("String from RAM\nnext line1\n"); //string from ram 109 | lcd.println(12345); //int 110 | lcd.println('A'); //char 111 | lcd.println(123456789L); //long 112 | lcd.println(98765.43); //float/double 113 | } 114 | 115 | 116 | void loop() 117 | { 118 | //do nothing 119 | } 120 | -------------------------------------------------------------------------------- /GraphicsLib/examples/Paint/Paint.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Paint Demonstration 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | //Declare only one display ! 19 | // MI0283QT2 lcd; //MI0283QT2 Adapter v1 20 | // MI0283QT9 lcd; //MI0283QT9 Adapter v1 21 | // DisplaySPI lcd; //SPI (GLCD-Shield or MI0283QT Adapter v2) 22 | // DisplayUART lcd; //UART (GLCD-Shield or MI0283QT Adapter v2) 23 | DisplayI2C lcd; //I2C (GLCD-Shield or MI0283QT Adapter v2) 24 | 25 | 26 | 27 | void writeCalData(void) 28 | { 29 | uint16_t i, addr=0; 30 | uint8_t *ptr; 31 | 32 | EEPROM.write(addr++, 0xAA); 33 | 34 | ptr = (uint8_t*)&lcd.tp_matrix; 35 | for(i=0; i < sizeof(CAL_MATRIX); i++) 36 | { 37 | EEPROM.write(addr++, *ptr++); 38 | } 39 | 40 | return; 41 | } 42 | 43 | 44 | uint8_t readCalData(void) 45 | { 46 | uint16_t i, addr=0; 47 | uint8_t *ptr; 48 | uint8_t c; 49 | 50 | c = EEPROM.read(addr++); 51 | if(c == 0xAA) 52 | { 53 | ptr = (uint8_t*)&lcd.tp_matrix; 54 | for(i=0; i < sizeof(CAL_MATRIX); i++) 55 | { 56 | *ptr++ = EEPROM.read(addr++); 57 | } 58 | return 0; 59 | } 60 | 61 | return 1; 62 | } 63 | 64 | 65 | void setup() 66 | { 67 | //init display 68 | lcd.begin(); 69 | //SPI Displays 70 | // lcd.begin(); //spi-clk=Fcpu/4 71 | // lcd.begin(SPI_CLOCK_DIV2); //spi-clk=Fcpu/2 72 | // lcd.begin(SPI_CLOCK_DIV16); //spi-clk=Fcpu/16 73 | // lcd.begin(SPI_CLOCK_DIV4, 8); //spi-clk=Fcpu/4, rst-pin=8 74 | //UART Displays 75 | // lcd.begin(5, 6, 7); //rx-pin=5, tx-pin=6, cs-pin=7 76 | // lcd.begin(5, 6, 7, 8); //rx-pin=5, tx-pin=6, cs-pin=7, rst-pin=8 77 | //I2C Displays 78 | // lcd.begin(0x20); //addr=0x20 79 | // lcd.begin(0x20, 8); //addr=0x20, rst-pin=8 80 | 81 | //set touchpanel calibration data 82 | lcd.touchRead(); 83 | if(lcd.touchZ() || readCalData()) //calibration data in EEPROM? 84 | { 85 | lcd.touchStartCal(); //calibrate touchpanel 86 | writeCalData(); //write data to EEPROM 87 | } 88 | 89 | //clear screen 90 | lcd.fillScreen(RGB(255,255,255)); 91 | 92 | //show backlight power and cal text 93 | lcd.led(50); //backlight 0...100% 94 | lcd.drawText(2, 2, "BL ", RGB(255,0,0), RGB(255,255,255), 1); 95 | lcd.drawInteger(20, 2, 50, DEC, RGB(255,0,0), RGB(255,255,255), 1); 96 | lcd.drawText(lcd.getWidth()-30, 2, "CAL", RGB(255,0,0), RGB(255,255,255), 1); 97 | } 98 | 99 | 100 | void loop() 101 | { 102 | char tmp[128]; 103 | static uint16_t last_x=0, last_y=0; 104 | static uint8_t led=60; 105 | unsigned long m; 106 | static unsigned long prevMillis=0; 107 | 108 | //service routine for touch panel 109 | lcd.touchRead(); 110 | 111 | if(lcd.touchZ()) //touch press? 112 | { 113 | //change backlight power 114 | if((lcd.touchX() < 45) && (lcd.touchY() < 15)) 115 | { 116 | m = millis(); 117 | if((m - prevMillis) > 800) //change only every 800ms 118 | { 119 | prevMillis = m; 120 | 121 | led += 10; 122 | if(led > 100) 123 | { 124 | led = 10; 125 | } 126 | lcd.led(led); 127 | lcd.drawText(2, 2, "BL ", RGB(255,0,0), RGB(255,255,255), 1); 128 | lcd.drawInteger(20, 2, led, DEC, RGB(255,0,0), RGB(255,255,255), 1); 129 | lcd.drawText(lcd.getWidth()-30, 2, "CAL", RGB(255,0,0), RGB(255,255,255), 1); 130 | } 131 | } 132 | 133 | //calibrate touch panel 134 | else if((lcd.touchX() > (lcd.getWidth()-30)) && (lcd.touchY() < 15)) 135 | { 136 | lcd.touchStartCal(); 137 | writeCalData(); 138 | lcd.drawText(2, 2, "BL ", RGB(255,0,0), RGB(255,255,255), 1); 139 | lcd.drawInteger(20, 2, led, DEC, RGB(255,0,0), RGB(255,255,255), 1); 140 | lcd.drawText(lcd.getWidth()-30, 2, "CAL", RGB(255,0,0), RGB(255,255,255), 1); 141 | } 142 | 143 | //draw line 144 | else if((last_x != lcd.touchX()) || (last_y != lcd.touchY())) 145 | { 146 | sprintf(tmp, "X:%03i Y:%03i P:%03i", lcd.touchX(), lcd.touchY(), lcd.touchZ()); 147 | lcd.drawText(50, 2, tmp, RGB(0,0,0), RGB(255,255,255), 1); 148 | 149 | if(last_x == 0) 150 | { 151 | lcd.drawPixel(lcd.touchX(), lcd.touchY(), RGB(0,0,0)); 152 | } 153 | else 154 | { 155 | lcd.drawLine(last_x, last_y, lcd.touchX(), lcd.touchY(), RGB(0,0,0)); 156 | } 157 | last_x = lcd.touchX(); 158 | last_y = lcd.touchY(); 159 | } 160 | } 161 | else 162 | { 163 | last_x = 0; 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /GraphicsLib/fonts.h: -------------------------------------------------------------------------------- 1 | #ifndef fonts_h 2 | #define fonts_h 3 | 4 | #if defined(__AVR__) 5 | # include 6 | #endif 7 | 8 | // All font data from Benedikt K. 9 | // http://www.mikrocontroller.net/topic/54860 10 | 11 | //Font selection (select only one font) 12 | //#define FONT_4X6 13 | //#define FONT_5X8 14 | //#define FONT_5X12 15 | //#define FONT_6X8 16 | //#define FONT_6X10 17 | //#define FONT_7X12 18 | #define FONT_8X8 19 | //#define FONT_8X12 20 | //#define FONT_8X14 21 | //#define FONT_10X16 22 | //#define FONT_12X16 23 | //#define FONT_12X20 24 | //#define FONT_16X26 25 | 26 | //if defined char range 0x20-0x7F otherwise 0x20-0xFF 27 | #define FONT_END7F 28 | 29 | #define FONT_START (0x20) //first character 30 | 31 | #if defined(FONT_4X6) 32 | # define FONT_WIDTH (4) 33 | # define FONT_HEIGHT (6) 34 | #elif defined(FONT_5X8) 35 | # define FONT_WIDTH (5) 36 | # define FONT_HEIGHT (8) 37 | #elif defined(FONT_5X12) 38 | # define FONT_WIDTH (5) 39 | # define FONT_HEIGHT (12) 40 | #elif defined(FONT_6X8) 41 | # define FONT_WIDTH (6) 42 | # define FONT_HEIGHT (8) 43 | #elif defined(FONT_6X10) 44 | # define FONT_WIDTH (6) 45 | # define FONT_HEIGHT (10) 46 | #elif defined(FONT_7X12) 47 | # define FONT_WIDTH (7) 48 | # define FONT_HEIGHT (12) 49 | #elif defined(FONT_8X8) 50 | # define FONT_WIDTH (8) 51 | # define FONT_HEIGHT (8) 52 | #elif defined(FONT_8X12) 53 | # define FONT_WIDTH (8) 54 | # define FONT_HEIGHT (12) 55 | #elif defined(FONT_8X14) 56 | # define FONT_WIDTH (8) 57 | # define FONT_HEIGHT (14) 58 | #elif defined(FONT_10X16) 59 | # define FONT_WIDTH (10) 60 | # define FONT_HEIGHT (16) 61 | #elif defined(FONT_12X16) 62 | # define FONT_WIDTH (12) 63 | # define FONT_HEIGHT (16) 64 | #elif defined(FONT_12X20) 65 | # define FONT_WIDTH (12) 66 | # define FONT_HEIGHT (20) 67 | #elif defined(FONT_16X26) 68 | # define FONT_WIDTH (16) 69 | # define FONT_HEIGHT (26) 70 | #else 71 | //# warning No font defined 72 | # define FONT_EMBEDDED //8x8 built-in font of MI0283QT-Adapter v2 73 | # define FONT_WIDTH (8) 74 | # define FONT_HEIGHT (8) 75 | #endif 76 | 77 | #if defined(__AVR__) 78 | extern const PROGMEM uint8_t font_PGM[]; 79 | #else 80 | extern const uint8_t font_PGM[]; 81 | #endif 82 | 83 | #endif //fonts_h 84 | -------------------------------------------------------------------------------- /GraphicsLib/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GraphicsLib", 3 | "version": "1.0.0", 4 | "keywords": "graphics, display, lcd", 5 | "description": "General Grahipcs Library", 6 | "include": "GraphicsLib", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "dependencies": 13 | { 14 | "name": "digitalWriteFast", 15 | "frameworks": "arduino" 16 | }, 17 | "frameworks": "arduino", 18 | "platforms": "atmelavr" 19 | } 20 | -------------------------------------------------------------------------------- /GraphicsLib/library.properties: -------------------------------------------------------------------------------- 1 | name=GraphicsLib 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=General Grahipcs Library 6 | paragraph=General Grahipcs Library 7 | category=Display 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /LCD_BackPack/LCD_BackPack.h: -------------------------------------------------------------------------------- 1 | //empty file, workaround for libraries containing only examples 2 | -------------------------------------------------------------------------------- /LCD_BackPack/examples/SerLCD/SerLCD.md: -------------------------------------------------------------------------------- 1 | # SerLCD Firmware for LCD-BackPack 2 | 3 | All **standard characters** received over the serial port (default 9600 baud) and I2C (default address 8) will be shown on the display. 4 | 5 | **Special characters:** 6 | ```0x0D``` (CR) -> new line, 7 | ```0x0A``` (LF) -> new line, 8 | ```0x08``` (Backspace) -> deleting last character 9 | 10 | ## Reset 11 | The firmware needs about 2s to start because of the Arduino bootloader. 12 | If ```0x12``` (18) is sent after this time and within 500ms then the serial baudrate will be set to 9600. 13 | 14 | ## Commands 15 | * **Display Commands** 16 | * Start Byte: ```0xFE``` (254) 17 | * Data Byte (HD44780 compatible commands): 18 | * ```0x01``` - clear display 19 | * ```0x08``` - display off 20 | * ```0x0C``` - display on + cursor off 21 | * ```0x0D``` - display on + blinking cursor on 22 | * ```0x0E``` - display on + cursor on 23 | * ```0x10``` - move cursor left 24 | * ```0x14``` - move cursor right 25 | * ```0x18``` - scroll left 26 | * ```0x1C``` - scroll right 27 | * ```0x80...``` - set cursor position 28 | * **Special Commands** 29 | * Start Byte: ```0x7C``` (124) 30 | * Data Byte: 31 | * ```0x01``` - backlight on (100%) 32 | * ```0x02``` - backlight off (0%) 33 | * ```0x03``` - 20 characters 34 | * ```0x04``` - 16 characters 35 | * ```0x05``` - 4 lines 36 | * ```0x06``` - 2 lines 37 | * ```0x07``` - 1 lines 38 | * ```0x08``` - re-init display 39 | * ```0x09``` - splash screen on/off 40 | * ```0x0A``` - save lines 1+2 for custom splash screen 41 | * ```0x0B``` - baudrate: 2400 42 | * ```0x0C``` - baudrate: 4800 43 | * ```0x0D``` - baudrate: 9600 44 | * ```0x0E``` - baudrate: 14400 45 | * ```0x0F``` - baudrate: 19200 46 | * ```0x10``` - baudrate: 38400 47 | * ```0x11``` - baudrate: 57600 48 | * ```0x12``` - baudrate: 115200 49 | * ```0x13``` - baudrate: 28800 50 | * ```0x14``` - save baudrate as default 51 | * ```0x15``` - contrast 0-100% 52 | * Parameter Byte: ```0x00...0x64``` 53 | * ```0x16``` - RGB backlight on/off 54 | * ```0x17``` - backlight 0-100% (1 byte and if RGB is on then 3 bytes) 55 | * Parameter Byte(s): ```0x00...0x64``` 56 | * ```0x80...0x9F``` - backlight 0-100% 57 | * ```0x80``` -> 0% 58 | * ```0x8C``` -> 40% 59 | * ```0x96``` -> 73% 60 | * ```0x9D``` -> 100% 61 | * ```0x9E``` -> 100% 62 | * ```0x9F``` -> 100% 63 | -------------------------------------------------------------------------------- /LCD_BackPack/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "LCD_BackPack", 3 | "version": "1.0.0", 4 | "keywords": "display, hd44780", 5 | "description": "LCD-BackPack (for HD44780 compatible displays)", 6 | "include": "LCD_BackPack", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "frameworks": "arduino", 13 | "platforms": "atmelavr" 14 | } 15 | -------------------------------------------------------------------------------- /LCD_BackPack/library.properties: -------------------------------------------------------------------------------- 1 | name=LCD_BackPack 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=LCD-BackPack (for HD44780 compatible displays) 6 | paragraph=LCD-BackPack (for HD44780 compatible displays) 7 | category=Display 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /MCP2515/MCP2515.h: -------------------------------------------------------------------------------- 1 | #ifndef MCP2515_h 2 | #define MCP2515_h 3 | 4 | 5 | //Data rate selection constants 6 | #define CAN_BAUD_10K 1 7 | #define CAN_BAUD_50K 2 8 | #define CAN_BAUD_100K 3 9 | #define CAN_BAUD_125K 4 10 | #define CAN_BAUD_250K 5 11 | #define CAN_BAUD_500K 6 12 | 13 | 14 | typedef struct 15 | { 16 | boolean isExtendedAdrs; 17 | unsigned long adrsValue; 18 | boolean rtr; 19 | byte dataLength; 20 | byte data[8]; 21 | } CANMSG; 22 | 23 | 24 | class MCP2515 25 | { 26 | public: 27 | static boolean initCAN(int baudConst); 28 | static boolean setCANNormalMode(boolean singleShot); 29 | static boolean setCANReceiveonlyMode(); 30 | static boolean receiveCANMessage(CANMSG *msg, unsigned long timeout); 31 | static boolean transmitCANMessage(CANMSG msg, unsigned long timeout); 32 | static byte getCANTxErrCnt(); 33 | static byte getCANRxErrCnt(); 34 | static long queryOBD(byte code); 35 | 36 | private: 37 | static boolean setCANBaud(int baudConst); 38 | static void writeReg(byte regno, byte val); 39 | static void writeRegBit(byte regno, byte bitno, byte val); 40 | static byte readReg(byte regno); 41 | }; 42 | 43 | 44 | #endif //MCP2515_h 45 | -------------------------------------------------------------------------------- /MCP2515/examples/Example/Example.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Example sketch for MCP2515 (CANdiy-Shield) 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | 9 | #define MODE 0 //0=rx, 1=tx 10 | 11 | int led2 = 7; 12 | int led3 = 8; 13 | int led13 = 13; 14 | CANMSG msg; 15 | MCP2515 can; 16 | 17 | 18 | void setup() 19 | { 20 | pinMode(led2, OUTPUT); 21 | pinMode(led3, OUTPUT); 22 | pinMode(led13, OUTPUT); 23 | digitalWrite(led2, HIGH); 24 | digitalWrite(led3, HIGH); 25 | digitalWrite(led13, HIGH); 26 | 27 | Serial.begin(9600); 28 | while(!Serial); 29 | Serial.println("Go..."); 30 | 31 | SPI.setClockDivider(SPI_CLOCK_DIV8); 32 | 33 | if(can.initCAN(CAN_BAUD_100K) == 0) 34 | { 35 | Serial.println("initCAN() failed"); 36 | digitalWrite(led2, LOW); 37 | digitalWrite(led3, LOW); 38 | digitalWrite(led13, LOW); 39 | while(1); 40 | } 41 | 42 | if(can.setCANNormalMode(LOW) == 0) //normal mode non single shot 43 | { 44 | Serial.println("setCANNormalMode() failed"); 45 | digitalWrite(led2, LOW); 46 | digitalWrite(led3, LOW); 47 | digitalWrite(led13, LOW); 48 | while(1); 49 | } 50 | } 51 | 52 | 53 | void loop() 54 | { 55 | #if MODE == 0 56 | //receiver 57 | int i = can.receiveCANMessage(&msg, 1000); 58 | if(i && (msg.data[2] == 123)) 59 | { 60 | digitalWrite(led2, HIGH); 61 | digitalWrite(led3, LOW); 62 | delay(100); 63 | digitalWrite(led2, LOW); 64 | digitalWrite(led3, HIGH); 65 | delay(100); 66 | Serial.println("data received"); 67 | } 68 | 69 | #else //MODE == 1 70 | //transmitter 71 | msg.adrsValue = 0x7df; 72 | msg.isExtendedAdrs = false; 73 | msg.rtr = false; 74 | msg.dataLength = 8; 75 | msg.data[0] = 0x02; 76 | msg.data[1] = 0x01; 77 | msg.data[2] = 123; 78 | msg.data[3] = 0; 79 | msg.data[4] = 0; 80 | msg.data[5] = 0; 81 | msg.data[6] = 0; 82 | msg.data[7] = 0; 83 | can.transmitCANMessage(msg, 1000); 84 | 85 | digitalWrite(led2, HIGH); 86 | digitalWrite(led3, LOW); 87 | delay(100); 88 | digitalWrite(led2, LOW); 89 | digitalWrite(led3, HIGH); 90 | Serial.println("data transmitted"); 91 | delay(2000); 92 | #endif 93 | 94 | digitalWrite(led13, HIGH); 95 | delay(100); 96 | digitalWrite(led13, LOW); 97 | delay(100); 98 | } 99 | -------------------------------------------------------------------------------- /MCP2515/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "MCP2515", 3 | "version": "1.0.0", 4 | "keywords": "spi, can-bus, canbus", 5 | "description": "MCP2515 CAN-Bus-Controller", 6 | "include": "MCP2515", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "frameworks": "arduino", 13 | "platforms": "atmelavr" 14 | } 15 | -------------------------------------------------------------------------------- /MCP2515/library.properties: -------------------------------------------------------------------------------- 1 | name=MCP2515 2 | version=1.0.0 3 | author=Frank Kienast (franksmicro) 4 | maintainer=Watterott 5 | sentence=MCP2515 CAN-Bus-Controller 6 | paragraph=MCP2515 CAN-Bus-Controller 7 | category=Communication 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /MI0283QT2/MI0283QT2.h: -------------------------------------------------------------------------------- 1 | #ifndef MI0283QT2_h 2 | #define MI0283QT2_h 3 | 4 | 5 | #include 6 | #include "GraphicsLib.h" 7 | 8 | 9 | class MI0283QT2 : public GraphicsLib 10 | { 11 | public: 12 | MI0283QT2(); 13 | 14 | void begin(uint_least8_t clock_div); 15 | void begin(void); 16 | void led(uint_least8_t power); 17 | void setOrientation(uint_least16_t o); 18 | void setArea(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1); 19 | void drawStart(void); 20 | void draw(uint_least16_t color); 21 | void drawStop(void); 22 | 23 | uint_least8_t touchRead(void); 24 | void touchStartCal(void); 25 | 26 | private: 27 | uint_least8_t lcd_clock_div; 28 | 29 | void reset(void); 30 | void wr_cmd(uint_least8_t cmd, uint_least8_t param); 31 | uint_least8_t rd_spi(void); 32 | void wr_spi(uint_least8_t data); 33 | }; 34 | 35 | 36 | #endif //MI0283QT2_h 37 | -------------------------------------------------------------------------------- /MI0283QT2/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "MI0283QT2", 3 | "version": "1.0.0", 4 | "keywords": "spi, graphics, display, lcd", 5 | "description": "MI0283QT-2 Display (HX8347D, SPI)", 6 | "include": "MI0283QT2", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "dependencies": 13 | [ 14 | { 15 | "name": "digitalWriteFast", 16 | "frameworks": "arduino" 17 | }, 18 | { 19 | "name": "GraphicsLib", 20 | "frameworks": "arduino" 21 | } 22 | ], 23 | "frameworks": "arduino", 24 | "platforms": "atmelavr" 25 | } 26 | -------------------------------------------------------------------------------- /MI0283QT2/library.properties: -------------------------------------------------------------------------------- 1 | name=MI0283QT2 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=MI0283QT-2 Display (HX8347D, SPI) 6 | paragraph=MI0283QT-2 Display (HX8347D, SPI) 7 | category=Display 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /MI0283QT9/MI0283QT9.h: -------------------------------------------------------------------------------- 1 | #ifndef MI0283QT9_h 2 | #define MI0283QT9_h 3 | 4 | 5 | #include 6 | #include "GraphicsLib.h" 7 | 8 | 9 | class MI0283QT9 : public GraphicsLib 10 | { 11 | public: 12 | MI0283QT9(); 13 | 14 | void begin(uint_least8_t clock_div); 15 | void begin(void); 16 | void led(uint_least8_t power); 17 | void invertDisplay(uint_least8_t invert); 18 | void setOrientation(uint_least16_t o); 19 | void setArea(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1); 20 | void drawStart(void); 21 | void draw(uint_least16_t color); 22 | void drawStop(void); 23 | 24 | uint_least8_t touchRead(void); 25 | void touchStartCal(void); 26 | 27 | private: 28 | uint_least8_t lcd_clock_div; 29 | 30 | void reset(void); 31 | void wr_cmd(uint_least8_t cmd); 32 | void wr_data16(uint_least16_t data); 33 | void wr_data(uint_least8_t data); 34 | uint_least8_t rd_spi(void); 35 | void wr_spi(uint_least8_t data); 36 | }; 37 | 38 | 39 | #endif //MI0283QT9_h 40 | -------------------------------------------------------------------------------- /MI0283QT9/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "MI0283QT9", 3 | "version": "1.0.0", 4 | "keywords": "spi, graphics, display, lcd", 5 | "description": "MI0283QT-9 / -9A / -11 Display (ILI9341, SPI)", 6 | "include": "MI0283QT9", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "dependencies": 13 | [ 14 | { 15 | "name": "digitalWriteFast", 16 | "frameworks": "arduino" 17 | }, 18 | { 19 | "name": "GraphicsLib", 20 | "frameworks": "arduino" 21 | } 22 | ], 23 | "frameworks": "arduino", 24 | "platforms": "atmelavr" 25 | } 26 | -------------------------------------------------------------------------------- /MI0283QT9/library.properties: -------------------------------------------------------------------------------- 1 | name=MI0283QT9 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=MI0283QT-9 / -9A / -11 Display (ILI9341, SPI) 6 | paragraph=MI0283QT-9 / -9A / -11 Display (ILI9341, SPI) 7 | category=Display 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Arduino Libraries 2 | 3 | Download all libraries [here](https://github.com/watterott/Arduino-Libs/archive/master.zip). 4 | 5 | ## [Documentation / Installation](http://learn.watterott.com/arduino/watterott-libs/) 6 | -------------------------------------------------------------------------------- /RV8523/RV8523.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | RV8523 RTC Lib for Arduino 3 | by Watterott electronic (www.watterott.com) 4 | */ 5 | 6 | #include 7 | #if defined(__AVR__) 8 | # include 9 | #endif 10 | #if ARDUINO >= 100 11 | # include "Arduino.h" 12 | #else 13 | # include "WProgram.h" 14 | #endif 15 | #include "Wire.h" 16 | #include "RV8523.h" 17 | 18 | 19 | #define I2C_ADDR (0xD0>>1) 20 | 21 | 22 | //-------------------- Constructor -------------------- 23 | 24 | 25 | RV8523::RV8523(void) 26 | { 27 | return; 28 | } 29 | 30 | 31 | //-------------------- Public -------------------- 32 | 33 | 34 | void RV8523::begin(void) 35 | { 36 | Wire.begin(); //init I2C lib 37 | } 38 | 39 | 40 | void RV8523::start(void) 41 | { 42 | uint8_t val; 43 | 44 | Wire.beginTransmission(I2C_ADDR); 45 | Wire.write(byte(0x00)); //control 1 46 | Wire.endTransmission(); 47 | Wire.requestFrom(I2C_ADDR, 1); 48 | val = Wire.read(); 49 | 50 | if(val & (1<<5)) 51 | { 52 | Wire.beginTransmission(I2C_ADDR); 53 | Wire.write(byte(0x00)); //control 1 54 | Wire.write(val & ~(1<<5)); //clear STOP (bit 5) 55 | Wire.endTransmission(); 56 | } 57 | 58 | return; 59 | } 60 | 61 | 62 | void RV8523::stop(void) 63 | { 64 | uint8_t val; 65 | 66 | Wire.beginTransmission(I2C_ADDR); 67 | Wire.write(byte(0x00)); //control 1 68 | Wire.endTransmission(); 69 | Wire.requestFrom(I2C_ADDR, 1); 70 | val = Wire.read(); 71 | 72 | if(!(val & (1<<5))) 73 | { 74 | Wire.beginTransmission(I2C_ADDR); 75 | Wire.write(byte(0x00)); //control 1 76 | Wire.write(val | (1<<5)); //set STOP (bit 5) 77 | Wire.endTransmission(); 78 | } 79 | 80 | return; 81 | } 82 | 83 | 84 | void RV8523::set12HourMode(void) //set 12 hour mode 85 | { 86 | uint8_t val; 87 | 88 | Wire.beginTransmission(I2C_ADDR); 89 | Wire.write(byte(0x00)); //control 1 90 | Wire.endTransmission(); 91 | Wire.requestFrom(I2C_ADDR, 1); 92 | val = Wire.read(); 93 | 94 | if(!(val & (1<<3))) 95 | { 96 | Wire.beginTransmission(I2C_ADDR); 97 | Wire.write(byte(0x00)); //control 1 98 | Wire.write(val | (1<<3)); //set 12 hour mode (bit 3) 99 | Wire.endTransmission(); 100 | } 101 | 102 | return; 103 | } 104 | 105 | 106 | void RV8523::set24HourMode(void) //set 24 hour mode 107 | { 108 | uint8_t val; 109 | 110 | Wire.beginTransmission(I2C_ADDR); 111 | Wire.write(byte(0x00)); //control 1 112 | Wire.endTransmission(); 113 | Wire.requestFrom(I2C_ADDR, 1); 114 | val = Wire.read(); 115 | 116 | if(val & (1<<3)) 117 | { 118 | Wire.beginTransmission(I2C_ADDR); 119 | Wire.write(byte(0x00)); //control 1 120 | Wire.write(val & ~(1<<3)); //set 12 hour mode (bit 3) 121 | Wire.endTransmission(); 122 | } 123 | 124 | return; 125 | } 126 | 127 | 128 | void RV8523::batterySwitchOver(int on) //activate/deactivate battery switch over mode 129 | { 130 | uint8_t val; 131 | 132 | Wire.beginTransmission(I2C_ADDR); 133 | Wire.write(byte(0x02)); //control 3 134 | Wire.endTransmission(); 135 | Wire.requestFrom(I2C_ADDR, 1); 136 | val = Wire.read(); 137 | if(val & 0xE0) 138 | { 139 | Wire.beginTransmission(I2C_ADDR); 140 | Wire.write(byte(0x02)); //control 3 141 | if(on) 142 | { 143 | Wire.write(val & ~0xE0); //battery switchover in standard mode 144 | } 145 | else 146 | { 147 | Wire.write(val | 0xE0); //battery switchover disabled 148 | } 149 | Wire.endTransmission(); 150 | } 151 | 152 | return; 153 | } 154 | 155 | 156 | void RV8523::get(uint8_t *sec, uint8_t *min, uint8_t *hour, uint8_t *day, uint8_t *month, uint16_t *year) 157 | { 158 | Wire.beginTransmission(I2C_ADDR); 159 | Wire.write(byte(0x03)); 160 | Wire.endTransmission(); 161 | 162 | Wire.requestFrom(I2C_ADDR, 7); 163 | *sec = bcd2bin(Wire.read() & 0x7F); 164 | *min = bcd2bin(Wire.read() & 0x7F); 165 | *hour = bcd2bin(Wire.read() & 0x3F); //24 hour mode 166 | *day = bcd2bin(Wire.read() & 0x3F); 167 | bcd2bin(Wire.read() & 0x07); //day of week 168 | *month = bcd2bin(Wire.read() & 0x1F); 169 | *year = bcd2bin(Wire.read()) + 2000; 170 | 171 | return; 172 | } 173 | 174 | 175 | void RV8523::get(int *sec, int *min, int *hour, int *day, int *month, int *year) 176 | { 177 | Wire.beginTransmission(I2C_ADDR); 178 | Wire.write(byte(0x03)); 179 | Wire.endTransmission(); 180 | 181 | Wire.requestFrom(I2C_ADDR, 7); 182 | *sec = bcd2bin(Wire.read() & 0x7F); 183 | *min = bcd2bin(Wire.read() & 0x7F); 184 | *hour = bcd2bin(Wire.read() & 0x3F); //24 hour mode 185 | *day = bcd2bin(Wire.read() & 0x3F); 186 | bcd2bin(Wire.read() & 0x07); //day of week 187 | *month = bcd2bin(Wire.read() & 0x1F); 188 | *year = bcd2bin(Wire.read()) + 2000; 189 | 190 | return; 191 | } 192 | 193 | 194 | void RV8523::set(uint8_t sec, uint8_t min, uint8_t hour, uint8_t day, uint8_t month, uint16_t year) 195 | { 196 | if(year > 2000) 197 | { 198 | year -= 2000; 199 | } 200 | 201 | Wire.beginTransmission(I2C_ADDR); 202 | Wire.write(byte(0x03)); 203 | Wire.write(bin2bcd(sec)); 204 | Wire.write(bin2bcd(min)); 205 | Wire.write(bin2bcd(hour)); 206 | Wire.write(bin2bcd(day)); 207 | Wire.write(bin2bcd(0)); 208 | Wire.write(bin2bcd(month)); 209 | Wire.write(bin2bcd(year)); 210 | Wire.endTransmission(); 211 | 212 | return; 213 | } 214 | 215 | 216 | void RV8523::set(int sec, int min, int hour, int day, int month, int year) 217 | { 218 | return set((uint8_t)sec, (uint8_t)min, (uint8_t)hour, (uint8_t)day, (uint8_t)month, (uint16_t)year); 219 | } 220 | 221 | 222 | //-------------------- Private -------------------- 223 | 224 | 225 | uint8_t RV8523::bin2bcd(uint8_t val) 226 | { 227 | return val + 6 * (val / 10); 228 | } 229 | 230 | 231 | uint8_t RV8523::bcd2bin(uint8_t val) 232 | { 233 | return val - 6 * (val >> 4); 234 | } 235 | -------------------------------------------------------------------------------- /RV8523/RV8523.h: -------------------------------------------------------------------------------- 1 | #ifndef RV8523_h 2 | #define RV8523_h 3 | 4 | 5 | #include 6 | 7 | 8 | class RV8523 9 | { 10 | public: 11 | RV8523(); 12 | 13 | void begin(void); 14 | void start(void); 15 | void stop(void); 16 | void get(uint8_t *sec, uint8_t *min, uint8_t *hour, uint8_t *day, uint8_t *month, uint16_t *year); 17 | void get(int *sec, int *min, int *hour, int *day, int *month, int *year); 18 | void set(uint8_t sec, uint8_t min, uint8_t hour, uint8_t day, uint8_t month, uint16_t year); 19 | void set(int sec, int min, int hour, int day, int month, int year); 20 | void set12HourMode(void); 21 | void set24HourMode(void); 22 | void batterySwitchOver(int on); 23 | 24 | private: 25 | uint8_t bin2bcd(uint8_t val); 26 | uint8_t bcd2bin(uint8_t val); 27 | }; 28 | 29 | 30 | #endif //RV8523_h 31 | -------------------------------------------------------------------------------- /RV8523/examples/Example/Example.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RV8523 RTC (Real-Time-Clock) Example 3 | 4 | Uno A4 (SDA), A5 (SCL) 5 | Mega 20 (SDA), 21 (SCL) 6 | Leonardo 2 (SDA), 3 (SCL) 7 | 8 | Note: To enable the I2C pull-up resistors on the RTC-Breakout, the jumper J1 has to be closed. 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | 15 | RV8523 rtc; 16 | 17 | 18 | void setup() 19 | { 20 | //init Serial port 21 | Serial.begin(9600); 22 | while(!Serial); //wait for serial port to connect - needed for Leonardo only 23 | 24 | //init RTC 25 | Serial.println("Init RTC..."); 26 | rtc.begin(); 27 | 28 | //set 12 hour mode 29 | // rtc.set12HourMode(); 30 | 31 | //set 24 hour mode 32 | // rtc.set24HourMode(); 33 | 34 | //set the date+time (only one time) 35 | // rtc.set(0, 0, 8, 24, 12, 2014); //08:00:00 24.12.2014 //sec, min, hour, day, month, year 36 | 37 | //stop/pause RTC 38 | // rtc.stop(); 39 | 40 | //start RTC 41 | rtc.start(); 42 | 43 | //When the power source is removed, the RTC will keep the time. 44 | rtc.batterySwitchOver(1); //battery switch over on 45 | 46 | //When the power source is removed, the RTC will not keep the time. 47 | // rtc.batterySwitchOver(0); //battery switch over off 48 | } 49 | 50 | 51 | void loop() 52 | { 53 | uint8_t sec, min, hour, day, month; 54 | uint16_t year; 55 | 56 | //get time from RTC 57 | rtc.get(&sec, &min, &hour, &day, &month, &year); 58 | 59 | //serial output 60 | Serial.print("\nTime: "); 61 | Serial.print(hour, DEC); 62 | Serial.print(":"); 63 | Serial.print(min, DEC); 64 | Serial.print(":"); 65 | Serial.print(sec, DEC); 66 | 67 | Serial.print("\nDate: "); 68 | Serial.print(day, DEC); 69 | Serial.print("."); 70 | Serial.print(month, DEC); 71 | Serial.print("."); 72 | Serial.print(year, DEC); 73 | 74 | //wait a second 75 | delay(1000); 76 | } 77 | -------------------------------------------------------------------------------- /RV8523/examples/SetClock/SetClock.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RV8523 RTC (Real-Time-Clock) Set Clock Example 3 | 4 | Uno A4 (SDA), A5 (SCL) 5 | Mega 20 (SDA), 21 (SCL) 6 | Leonardo 2 (SDA), 3 (SCL) 7 | 8 | Note: To enable the I2C pull-up resistors on the RTC-Breakout, the jumper J1 has to be closed. 9 | 10 | This sketch allows to set the time using the serial console. On linux use a command like: 11 | 12 | stty -F /dev/ttyUSB1 speed 9600 13 | date '+T%H%M%S%d%m%Y' > /dev/ttyUSB1 14 | 15 | to read the current local time from the serial console. Or just type a string like 16 | 17 | T23595924122015 18 | 19 | to set the clock to 23:59:59 24th of December 2015 using Arduinos/Genuinos serial monitor. 20 | 21 | Type an arbitary string not beginning with 'T' to show the current time. 22 | */ 23 | 24 | #include 25 | #include 26 | 27 | 28 | #define BUFF_MAX 32 29 | 30 | RV8523 rtc; 31 | unsigned int recv_size = 0; 32 | char recv[BUFF_MAX]; 33 | 34 | 35 | void setup() 36 | { 37 | //init Serial port 38 | Serial.begin(9600); 39 | while(!Serial); //wait for serial port to connect - needed for Leonardo only 40 | 41 | //init RTC 42 | Serial.println("Init RTC..."); 43 | rtc.begin(); 44 | 45 | //set 24 hour mode 46 | rtc.set24HourMode(); 47 | 48 | //start RTC 49 | rtc.start(); 50 | 51 | //When the power source is removed, the RTC will keep the time. 52 | rtc.batterySwitchOver(1); //battery switch over on 53 | } 54 | 55 | 56 | void loop() 57 | { 58 | if (Serial.available() > 0) { 59 | setClock(); 60 | } 61 | } 62 | 63 | 64 | void setClock() 65 | { 66 | char in; 67 | 68 | in = Serial.read(); 69 | Serial.print(in); 70 | 71 | if((in == 10 || in == 13) && (recv_size > 0)) 72 | { 73 | parseCmd(recv, recv_size); 74 | printTime(); 75 | recv_size = 0; 76 | recv[0] = 0; 77 | return; 78 | } 79 | else if (in < 48 || in > 122) //ignore ~[0-9A-Za-z] 80 | { 81 | //do nothing 82 | } 83 | else if (recv_size > BUFF_MAX - 2) //drop lines that are too long 84 | { 85 | recv_size = 0; 86 | recv[0] = 0; 87 | } 88 | else if (recv_size < BUFF_MAX - 2) 89 | { 90 | recv[recv_size] = in; 91 | recv[recv_size + 1] = 0; 92 | recv_size += 1; 93 | } 94 | } 95 | 96 | 97 | // parse the time string and set the clock accordingly 98 | void parseCmd(char *cmd, int cmdsize) 99 | { 100 | uint8_t i; 101 | uint8_t reg_val; 102 | char buff[BUFF_MAX]; 103 | 104 | //ThhmmssDDMMYYYY aka set time 105 | if (cmd[0] == 84 && cmdsize == 15) 106 | { 107 | rtc.set( 108 | (int)inp2toi(cmd, 5), 109 | (int)inp2toi(cmd, 3), 110 | (int)inp2toi(cmd, 1), 111 | (int)inp2toi(cmd, 7), 112 | (int)inp2toi(cmd, 9), 113 | (int)inp2toi(cmd, 11) * 100 + inp2toi(cmd, 13) 114 | ); //sec, min, hour, day, month, year 115 | Serial.println("OK"); 116 | } 117 | } 118 | 119 | 120 | // just output the time 121 | void printTime() 122 | { 123 | uint8_t sec, min, hour, day, month; 124 | uint16_t year; 125 | 126 | //get time from RTC 127 | rtc.get(&sec, &min, &hour, &day, &month, &year); 128 | 129 | //serial output 130 | Serial.print("\nTime: "); 131 | Serial.print(hour, DEC); 132 | Serial.print(":"); 133 | Serial.print(min, DEC); 134 | Serial.print(":"); 135 | Serial.print(sec, DEC); 136 | 137 | Serial.print("\nDate: "); 138 | Serial.print(day, DEC); 139 | Serial.print("."); 140 | Serial.print(month, DEC); 141 | Serial.print("."); 142 | Serial.print(year, DEC); 143 | } 144 | 145 | 146 | uint8_t inp2toi(char *cmd, const uint16_t seek) 147 | { 148 | uint8_t rv; 149 | rv = (cmd[seek] - 48) * 10 + cmd[seek + 1] - 48; 150 | return rv; 151 | } 152 | -------------------------------------------------------------------------------- /RV8523/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "RV8523", 3 | "version": "1.0.0", 4 | "keywords": "i2c, rtc, time, clock", 5 | "description": "RV-8523 RTC (Real-Time-Clock)", 6 | "include": "RV8523", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "frameworks": "arduino", 13 | "platforms": "atmelavr" 14 | } 15 | -------------------------------------------------------------------------------- /RV8523/library.properties: -------------------------------------------------------------------------------- 1 | name=RV8523 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=RV-8523 RTC (Real-Time-Clock) 6 | paragraph=RV-8523 RTC (Real-Time-Clock) 7 | category=Timing 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /RedFly/RedFlyClient.h: -------------------------------------------------------------------------------- 1 | #ifndef REDFLYCLIENT_h 2 | #define REDFLYCLIENT_h 3 | 4 | 5 | #include 6 | #if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) 7 | # include 8 | #endif 9 | #include "Print.h" 10 | #include "RedFly.h" 11 | #include "Server.h" 12 | 13 | 14 | class RedFlyClient : public Server 15 | { 16 | public: 17 | RedFlyClient(void); 18 | RedFlyClient(uint8_t socket); 19 | RedFlyClient(uint8_t *ip, uint16_t port); 20 | RedFlyClient(uint8_t *ip, uint16_t port, uint16_t lport); 21 | ~RedFlyClient(void); 22 | 23 | virtual void begin(void); //same as connect() 24 | virtual void beginUDP(void); //same as connect() 25 | virtual int connect(void); 26 | virtual int connectUDP(void); 27 | virtual int connect(uint8_t *ip, uint16_t port); 28 | virtual int connectUDP(uint8_t *ip, uint16_t port); 29 | virtual int connect(uint8_t *ip, uint16_t port, uint16_t lport); 30 | virtual int connectUDP(uint8_t *ip, uint16_t port, uint16_t lport); 31 | virtual int connect(char *host, uint16_t port); 32 | virtual int connectUDP(char *host, uint16_t port); 33 | int connectSocket(uint8_t p); 34 | virtual uint8_t connected(void); 35 | virtual void stop(void); 36 | uint8_t status(void); 37 | uint8_t getsocket(void); 38 | 39 | virtual int available(void); 40 | virtual int read(void); 41 | virtual int read(uint8_t *s, size_t sz); 42 | //virtual int peek(void); //not available 43 | virtual void flush(void); 44 | virtual size_t write(uint8_t b); 45 | virtual size_t write(const char *s); 46 | virtual size_t write(const uint8_t *s, size_t sz); 47 | virtual size_t print_P(PGM_P s); 48 | virtual size_t println_P(PGM_P s); 49 | 50 | virtual operator bool(); 51 | 52 | using Print::write; 53 | 54 | private: 55 | uint8_t c_socket; 56 | uint8_t c_ip[4]; 57 | uint16_t c_port; 58 | uint16_t c_lport; 59 | uint8_t proto, error; 60 | }; 61 | 62 | 63 | #endif //REDFLYCLIENT_h 64 | -------------------------------------------------------------------------------- /RedFly/RedFlyNBNS.h: -------------------------------------------------------------------------------- 1 | #ifndef REDFLYNBNS_h 2 | #define REDFLYNBNS_h 3 | 4 | 5 | #include 6 | #if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) 7 | # include 8 | #endif 9 | #include "RedFlyServer.h" 10 | 11 | 12 | class RedFlyNBNS : RedFlyServer 13 | { 14 | public: 15 | RedFlyNBNS(void); 16 | RedFlyNBNS(char *name); 17 | ~RedFlyNBNS(void); 18 | 19 | void setName(char *name); 20 | #if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) 21 | void setNamePGM(PGM_P name); 22 | #endif 23 | uint8_t service(void); 24 | 25 | private: 26 | char devname[16+1]; 27 | 28 | uint8_t decode(char *dst, char *src); 29 | void encode(char *dst, char *src, uint8_t type); 30 | }; 31 | 32 | 33 | #endif //REDFLYNBNS_h 34 | -------------------------------------------------------------------------------- /RedFly/RedFlyServer.h: -------------------------------------------------------------------------------- 1 | #ifndef REDFLYSERVER_h 2 | #define REDFLYSERVER_h 3 | 4 | 5 | #include 6 | #if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) 7 | # include 8 | #endif 9 | #include "Print.h" 10 | #include "RedFly.h" 11 | #include "Server.h" 12 | 13 | 14 | class RedFlyServer : public Server 15 | { 16 | public: 17 | RedFlyServer(void); 18 | RedFlyServer(uint16_t port); 19 | ~RedFlyServer(void); 20 | 21 | virtual void begin(void); //same as connect() 22 | virtual void beginUDP(void); //same as connect() 23 | virtual int connect(void); 24 | virtual int connectUDP(void); 25 | virtual int connect(uint16_t port); 26 | virtual int connectUDP(uint16_t port); 27 | int connectSocket(uint8_t p); 28 | virtual uint8_t connected(void); 29 | virtual void stop(void); 30 | uint8_t status(void); 31 | uint8_t getsocket(void); 32 | void getip(uint8_t *ip); 33 | uint16_t getport(void); 34 | 35 | virtual int available(void); 36 | virtual int read(void); 37 | virtual int read(uint8_t *s, size_t sz); 38 | //virtual int peek(void); //not available 39 | virtual void flush(void); 40 | virtual size_t write(uint8_t b); 41 | virtual size_t write(const char *s); 42 | virtual size_t write(const uint8_t *s, size_t sz); 43 | virtual size_t print_P(PGM_P s); 44 | virtual size_t println_P(PGM_P s); 45 | 46 | virtual operator bool(); 47 | 48 | using Print::write; 49 | 50 | private: 51 | uint16_t s_port; 52 | uint8_t s_socket; 53 | uint8_t c_ip[4]; 54 | uint16_t c_port; 55 | uint8_t proto, error; 56 | }; 57 | 58 | 59 | #endif //REDFLYSERVER_h 60 | -------------------------------------------------------------------------------- /RedFly/examples/Adhoc/Adhoc.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Ad-hoc Test 3 | 4 | This sketch connects two RedFly-Shields using an ad-hoc network 5 | and synchronizes the state of a switch connected to pin A5 and GND. 6 | One shield is the server and the other one is the client. 7 | Use the Serial Monitor for configuration (9600 Baud). 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | uint8_t led_pin = 13; //pin 13 has a LED connected on most Arduino boards 17 | uint8_t sw_pin = A5; //connect switch to pin A5 and GND 18 | 19 | uint8_t working_mode = 0; //mode: 0=server, 1=client 20 | uint16_t comm_port = 1234; //communication port 21 | uint32_t last_time = 0; 22 | uint8_t last_state = 0; 23 | 24 | byte ip_server[] = { 192,168,0,50 }; //ip from server shield 25 | byte ip_client[] = { 192,168,0,51 }; //ip from client shield 26 | 27 | 28 | RedFlyClient client(ip_server, comm_port); //create client class 29 | RedFlyServer server(comm_port); //create server class 30 | 31 | 32 | //debug output functions (9600 Baud, 8N2) 33 | //Leonardo boards use USB for communication, so we dont need to disable the RedFly 34 | void debugout(char *s) 35 | { 36 | #if defined(__AVR_ATmega32U4__) 37 | Serial.print(s); 38 | #else 39 | RedFly.disable(); 40 | Serial.print(s); 41 | RedFly.enable(); 42 | #endif 43 | } 44 | 45 | void debugoutln(char *s) 46 | { 47 | #if defined(__AVR_ATmega32U4__) 48 | Serial.println(s); 49 | #else 50 | RedFly.disable(); 51 | Serial.println(s); 52 | RedFly.enable(); 53 | #endif 54 | } 55 | 56 | 57 | void setup() 58 | { 59 | uint8_t ret; 60 | 61 | //set pin config 62 | pinMode(led_pin, OUTPUT); 63 | digitalWrite(led_pin, LOW); 64 | pinMode(sw_pin, INPUT); 65 | digitalWrite(sw_pin, HIGH); //pull-up on 66 | 67 | #if defined(__AVR_ATmega32U4__) //Leonardo boards use USB for communication 68 | Serial.begin(9600); //init serial port and set baudrate 69 | while(!Serial); //wait for serial port to connect (needed for Leonardo only) 70 | #endif 71 | 72 | ret = RedFly.init(); //9600 baud, HIGH_POWER 73 | if(ret) 74 | { 75 | debugoutln("INIT ERR"); //there are problems with the communication between the Arduino and the RedFly 76 | for(;;); //do nothing forevermore 77 | } 78 | else 79 | { 80 | RedFly.disable(); 81 | Serial.println("Press 0 for server or 1 for client"); 82 | while(Serial.available() == 0); 83 | working_mode = Serial.read() - '0'; 84 | while(Serial.available() != 0){ Serial.read(); } 85 | if(working_mode == 0) //server 86 | { 87 | Serial.println("Server..."); 88 | } 89 | else 90 | { 91 | Serial.println("Client..."); 92 | } 93 | RedFly.enable(); 94 | 95 | if(working_mode == 0) //server 96 | { 97 | do 98 | { 99 | delay(1000); 100 | ret = RedFly.join("ADHOC", "1A2B3C4D5E", IBSS_CREATOR, 1); //create ad-hoc network 101 | } 102 | while(ret != 0); 103 | ret = RedFly.begin(ip_server); //use static ip 104 | } 105 | else //client 106 | { 107 | do 108 | { 109 | delay(1000); 110 | RedFly.scan(); //scan for wireless networks (must be run before join command) 111 | ret = RedFly.join("ADHOC", "1A2B3C4D5E", IBSS_JOINER); //join ad-hoc network 112 | } 113 | while(ret != 0); 114 | ret = RedFly.begin(ip_client); //use static ip 115 | } 116 | 117 | if(ret) 118 | { 119 | debugoutln("BEGIN ERR"); 120 | RedFly.disconnect(); 121 | for(;;); //do nothing forevermore 122 | } 123 | else 124 | { 125 | debugoutln("started"); 126 | } 127 | } 128 | } 129 | 130 | 131 | void loop() 132 | { 133 | uint8_t c; 134 | unsigned long ms = millis(); 135 | 136 | if(working_mode == 0) //server 137 | { 138 | if(!server.connected()) //server port open? 139 | { 140 | server.stop(); 141 | server.begin(); 142 | } 143 | else if(server.available()) //new data available 144 | { 145 | c = (server.read()!=0) ? HIGH : LOW; 146 | digitalWrite(led_pin, c); 147 | } 148 | else if((ms-last_time) > 100) //check switch every 100ms 149 | { 150 | last_time = ms; //save time 151 | c = digitalRead(sw_pin); //read switch 152 | if(c != last_state) //switch state changed? 153 | { 154 | last_state = c; 155 | server.write(c); //send data over WLAN 156 | } 157 | } 158 | } 159 | else //client 160 | { 161 | if(!client.connected()) //client connected to server? 162 | { 163 | client.stop(); 164 | client.connect(); 165 | } 166 | else if(client.available()) //new data available 167 | { 168 | c = (client.read()!=0) ? HIGH : LOW; 169 | digitalWrite(led_pin, c); 170 | } 171 | else if((ms-last_time) > 100) //check switch every 100ms 172 | { 173 | last_time = ms; //save time 174 | c = digitalRead(sw_pin); //read switch 175 | if(c != last_state) //switch state changed? 176 | { 177 | last_state = c; 178 | client.write(c); //send data over WLAN 179 | } 180 | } 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /RedFly/examples/EchoTest/EchoTest.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Echo Test (Socket API) 3 | 4 | This sketch acts as a echo server using a RedFly-Shield. 5 | All received data will be resend to the client. 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | 12 | byte ip[] = { 192,168, 0, 30 }; //ip from shield (server) 13 | byte netmask[] = { 255,255,255, 0 }; //netmask 14 | 15 | #define TCP_PORT (80) //local TCP port on the shield 16 | #define UDP_PORT (80) //local UDP port on the shield 17 | 18 | uint8_t hTCP=INVALID_SOCKET, hUDP=INVALID_SOCKET; //socket handles 19 | 20 | 21 | //debug output functions (9600 Baud, 8N2) 22 | //Leonardo boards use USB for communication, so we dont need to disable the RedFly 23 | void debugout(char *s) 24 | { 25 | #if defined(__AVR_ATmega32U4__) 26 | Serial.print(s); 27 | #else 28 | RedFly.disable(); 29 | Serial.print(s); 30 | RedFly.enable(); 31 | #endif 32 | } 33 | 34 | void debugoutln(char *s) 35 | { 36 | #if defined(__AVR_ATmega32U4__) 37 | Serial.println(s); 38 | #else 39 | RedFly.disable(); 40 | Serial.println(s); 41 | RedFly.enable(); 42 | #endif 43 | } 44 | 45 | 46 | void setup() 47 | { 48 | uint8_t ret; 49 | 50 | #if defined(__AVR_ATmega32U4__) //Leonardo boards use USB for communication 51 | Serial.begin(9600); //init serial port and set baudrate 52 | while(!Serial); //wait for serial port to connect (needed for Leonardo only) 53 | #endif 54 | 55 | //init the WiFi module on the shield 56 | // ret = RedFly.init(br, pwr) //br=9600|19200|38400|57600|115200|200000|230400, pwr=LOW_POWER|MED_POWER|HIGH_POWER 57 | // ret = RedFly.init(pwr) //9600 baud, pwr=LOW_POWER|MED_POWER|HIGH_POWER 58 | // ret = RedFly.init() //9600 baud, HIGH_POWER 59 | ret = RedFly.init(); 60 | if(ret) 61 | { 62 | debugoutln("INIT ERR"); //there are problems with the communication between the Arduino and the RedFly 63 | } 64 | else 65 | { 66 | //scan for wireless networks (must be run before join command) 67 | RedFly.scan(); 68 | 69 | //join network 70 | // ret = join("wlan-ssid", "wlan-passw", INFRASTRUCTURE or IBSS_JOINER or IBSS_CREATOR, chn, authmode) //join infrastructure or ad-hoc network, or create ad-hoc network 71 | // ret = join("wlan-ssid", "wlan-passw", IBSS_CREATOR, chn) //create ad-hoc network with password, channel 1-14 72 | // ret = join("wlan-ssid", IBSS_CREATOR, chn) //create ad-hoc network, channel 1-14 73 | // ret = join("wlan-ssid", "wlan-passw", INFRASTRUCTURE or IBSS_JOINER) //join infrastructure or ad-hoc network with password 74 | // ret = join("wlan-ssid", INFRASTRUCTURE or IBSS_JOINER) //join infrastructure or ad-hoc network 75 | // ret = join("wlan-ssid", "wlan-passw") //join infrastructure network with password 76 | // ret = join("wlan-ssid") //join infrastructure network 77 | ret = RedFly.join("wlan-ssid", "wlan-passw", INFRASTRUCTURE); 78 | if(ret) 79 | { 80 | debugoutln("JOIN ERR"); 81 | for(;;); //do nothing forevermore 82 | } 83 | else 84 | { 85 | //set ip config 86 | // ret = RedFly.begin(); //DHCP 87 | // ret = RedFly.begin(1 or 2); //1=DHCP or 2=Auto-IP 88 | // ret = RedFly.begin(ip); 89 | // ret = RedFly.begin(ip, dnsserver); 90 | // ret = RedFly.begin(ip, dnsserver, gateway); 91 | // ret = RedFly.begin(ip, dnsserver, gateway, netmask); 92 | ret = RedFly.begin(ip, 0, 0, netmask); 93 | if(ret) 94 | { 95 | debugoutln("BEGIN ERR"); 96 | RedFly.disconnect(); 97 | for(;;); //do nothing forevermore 98 | } 99 | } 100 | } 101 | } 102 | 103 | 104 | void loop() 105 | { 106 | uint8_t sock, buf[64], *ptr; 107 | uint16_t buf_len, rd, len; 108 | uint16_t port; //incomming UDP port 109 | uint8_t ip[4]; //incomming UDP ip 110 | 111 | //check if sockets are opened 112 | if(RedFly.socketClosed(hTCP)) 113 | { 114 | hTCP = RedFly.socketListen(PROTO_TCP, TCP_PORT); //open TCP socket 115 | } 116 | if(RedFly.socketClosed(hUDP)) 117 | { 118 | hUDP = RedFly.socketListen(PROTO_UDP, UDP_PORT); //open UDP socket 119 | } 120 | 121 | //get data 122 | sock = 0xFF; //0xFF = return data from all open sockets 123 | ptr = buf; 124 | buf_len = 0; 125 | do 126 | { 127 | rd = RedFly.socketRead(&sock, &len, ip, &port, ptr, sizeof(buf)-buf_len); 128 | if((rd != 0) && (rd != 0xFFFF)) //0xFFFF = connection closed 129 | { 130 | ptr += rd; 131 | buf_len += rd; 132 | } 133 | }while(len != 0); //len contains the data size from rx buffer 134 | 135 | //send data 136 | if(buf_len && (sock != INVALID_SOCKET)) //data received for transmitting? 137 | { 138 | if(sock == hTCP) 139 | { 140 | RedFly.socketSend(hTCP, buf, buf_len); //send data to TCP socket 141 | } 142 | else if(sock == hUDP) 143 | { 144 | RedFly.socketSend(hUDP, buf, buf_len, ip, port); //send data to UDP socket 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /RedFly/examples/FWupdate/FWupdate.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Firmware Update 3 | 4 | Sketch that should be loaded on a Firmare Update. 5 | */ 6 | 7 | #define RX_PIN (0) 8 | #define TX_PIN (1) 9 | #define RST_PIN (2) 10 | #define CS_PIN (3) 11 | 12 | 13 | void setup() 14 | { 15 | pinMode(RX_PIN, INPUT); 16 | 17 | pinMode(TX_PIN, INPUT); 18 | 19 | pinMode(RST_PIN, OUTPUT); 20 | digitalWrite(RST_PIN, HIGH); //reset off 21 | 22 | pinMode(CS_PIN, OUTPUT); 23 | digitalWrite(CS_PIN, HIGH); //disable 24 | 25 | while(1); 26 | } 27 | 28 | 29 | void loop() 30 | { 31 | } 32 | -------------------------------------------------------------------------------- /RedFly/examples/Infrastructure/Infrastructure.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Infrastructure Test 3 | 4 | This sketch connects two RedFly-Shields using an infrastructure network 5 | and synchronizes the state of a switch connected to pin A5 and GND. 6 | One shield is the server and the other one is the client. 7 | Use the Serial Monitor for configuration (9600 Baud). 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | uint8_t led_pin = 13; //pin 13 has a LED connected on most Arduino boards 17 | uint8_t sw_pin = A5; //connect switch to pin A5 and GND 18 | 19 | uint8_t working_mode = 0; //mode: 0=server, 1=client 20 | uint16_t comm_port = 1234; //communication port 21 | uint32_t last_time = 0; 22 | uint8_t last_state = 0; 23 | 24 | byte ip_server[] = { 192,168,0,50 }; //ip from server shield 25 | byte ip_client[] = { 192,168,0,51 }; //ip from client shield 26 | 27 | 28 | RedFlyClient client(ip_server, comm_port); //create client class 29 | RedFlyServer server(comm_port); //create server class 30 | 31 | 32 | //debug output functions (9600 Baud, 8N2) 33 | //Leonardo boards use USB for communication, so we dont need to disable the RedFly 34 | void debugout(char *s) 35 | { 36 | #if defined(__AVR_ATmega32U4__) 37 | Serial.print(s); 38 | #else 39 | RedFly.disable(); 40 | Serial.print(s); 41 | RedFly.enable(); 42 | #endif 43 | } 44 | 45 | void debugoutln(char *s) 46 | { 47 | #if defined(__AVR_ATmega32U4__) 48 | Serial.println(s); 49 | #else 50 | RedFly.disable(); 51 | Serial.println(s); 52 | RedFly.enable(); 53 | #endif 54 | } 55 | 56 | 57 | void setup() 58 | { 59 | uint8_t ret; 60 | 61 | //set pin config 62 | pinMode(led_pin, OUTPUT); 63 | digitalWrite(led_pin, LOW); 64 | pinMode(sw_pin, INPUT); 65 | digitalWrite(sw_pin, HIGH); //pull-up on 66 | 67 | #if defined(__AVR_ATmega32U4__) //Leonardo boards use USB for communication 68 | Serial.begin(9600); //init serial port and set baudrate 69 | while(!Serial); //wait for serial port to connect (needed for Leonardo only) 70 | #endif 71 | 72 | ret = RedFly.init(); //9600 baud, HIGH_POWER 73 | if(ret) 74 | { 75 | debugoutln("INIT ERR"); //there are problems with the communication between the Arduino and the RedFly 76 | for(;;); //do nothing forevermore 77 | } 78 | else 79 | { 80 | RedFly.disable(); 81 | Serial.println("Press 0 for server or 1 for client"); 82 | while(Serial.available() == 0); 83 | working_mode = Serial.read() - '0'; 84 | while(Serial.available() != 0){ Serial.read(); } 85 | if(working_mode == 0) //server 86 | { 87 | Serial.println("Server..."); 88 | } 89 | else 90 | { 91 | Serial.println("Client..."); 92 | } 93 | RedFly.enable(); 94 | 95 | do 96 | { 97 | delay(1000); 98 | ret = RedFly.join("wlan-ssid", "wlan-passw", INFRASTRUCTURE); 99 | } 100 | while(ret != 0); 101 | 102 | if(working_mode == 0) //server 103 | { 104 | ret = RedFly.begin(ip_server); //use static ip 105 | } 106 | else //client 107 | { 108 | ret = RedFly.begin(ip_client); //use static ip 109 | } 110 | 111 | if(ret) 112 | { 113 | debugoutln("BEGIN ERR"); 114 | RedFly.disconnect(); 115 | for(;;); //do nothing forevermore 116 | } 117 | else 118 | { 119 | debugoutln("started"); 120 | } 121 | } 122 | } 123 | 124 | 125 | void loop() 126 | { 127 | uint8_t c; 128 | unsigned long ms = millis(); 129 | 130 | if(working_mode == 0) //server 131 | { 132 | if(!server.connected()) //server port open? 133 | { 134 | server.stop(); 135 | server.begin(); 136 | } 137 | else if(server.available()) //new data available 138 | { 139 | c = (server.read()!=0) ? HIGH : LOW; 140 | digitalWrite(led_pin, c); 141 | } 142 | else if((ms-last_time) > 100) //check switch every 100ms 143 | { 144 | last_time = ms; //save time 145 | c = digitalRead(sw_pin); //read switch 146 | if(c != last_state) //switch state changed? 147 | { 148 | last_state = c; 149 | server.write(c); //send data over WLAN 150 | } 151 | } 152 | } 153 | else //client 154 | { 155 | if(!client.connected()) //client connected to server? 156 | { 157 | client.stop(); 158 | client.connect(); 159 | } 160 | else if(client.available()) //new data available 161 | { 162 | c = (client.read()!=0) ? HIGH : LOW; 163 | digitalWrite(led_pin, c); 164 | } 165 | else if((ms-last_time) > 100) //check switch every 100ms 166 | { 167 | last_time = ms; //save time 168 | c = digitalRead(sw_pin); //read switch 169 | if(c != last_state) //switch state changed? 170 | { 171 | last_state = c; 172 | client.write(c); //send data over WLAN 173 | } 174 | } 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /RedFly/examples/NBNS/NBNS.ino: -------------------------------------------------------------------------------- 1 | /* 2 | NBNS (NetBIOS Name Service) Test 3 | 4 | This sketch shows the basic NetBIOS Name Service (NBNS) support in action. 5 | For testing, open in your browser http://redfly/ 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | byte ip[] = { 192,168, 0, 30 }; //ip from shield (client) 15 | 16 | //initialize the server library with the port 17 | //you want to use (port 80 is default for HTTP) 18 | RedFlyServer server(80); 19 | 20 | //initialize the NBNS library with the device name (max. 16 characters) 21 | RedFlyNBNS NBNS("REDFLY"); 22 | 23 | 24 | //debug output functions (9600 Baud, 8N2) 25 | //Leonardo boards use USB for communication, so we dont need to disable the RedFly 26 | void debugout(char *s) 27 | { 28 | #if defined(__AVR_ATmega32U4__) 29 | Serial.print(s); 30 | #else 31 | RedFly.disable(); 32 | Serial.print(s); 33 | RedFly.enable(); 34 | #endif 35 | } 36 | 37 | void debugoutln(char *s) 38 | { 39 | #if defined(__AVR_ATmega32U4__) 40 | Serial.println(s); 41 | #else 42 | RedFly.disable(); 43 | Serial.println(s); 44 | RedFly.enable(); 45 | #endif 46 | } 47 | 48 | 49 | void setup() 50 | { 51 | uint8_t ret; 52 | 53 | #if defined(__AVR_ATmega32U4__) //Leonardo boards use USB for communication 54 | Serial.begin(9600); //init serial port and set baudrate 55 | while(!Serial); //wait for serial port to connect (needed for Leonardo only) 56 | #endif 57 | 58 | //init the WiFi module on the shield 59 | // ret = RedFly.init(br, pwr) //br=9600|19200|38400|57600|115200|200000|230400, pwr=LOW_POWER|MED_POWER|HIGH_POWER 60 | // ret = RedFly.init(pwr) //9600 baud, pwr=LOW_POWER|MED_POWER|HIGH_POWER 61 | // ret = RedFly.init() //9600 baud, HIGH_POWER 62 | ret = RedFly.init(); 63 | if(ret) 64 | { 65 | debugoutln("INIT ERR"); //there are problems with the communication between the Arduino and the RedFly 66 | } 67 | else 68 | { 69 | //scan for wireless networks (must be run before join command) 70 | RedFly.scan(); 71 | 72 | //join network 73 | // ret = join("wlan-ssid", "wlan-passw", INFRASTRUCTURE or IBSS_JOINER or IBSS_CREATOR, chn, authmode) //join infrastructure or ad-hoc network, or create ad-hoc network 74 | // ret = join("wlan-ssid", "wlan-passw", IBSS_CREATOR, chn) //create ad-hoc network with password, channel 1-14 75 | // ret = join("wlan-ssid", IBSS_CREATOR, chn) //create ad-hoc network, channel 1-14 76 | // ret = join("wlan-ssid", "wlan-passw", INFRASTRUCTURE or IBSS_JOINER) //join infrastructure or ad-hoc network with password 77 | // ret = join("wlan-ssid", INFRASTRUCTURE or IBSS_JOINER) //join infrastructure or ad-hoc network 78 | // ret = join("wlan-ssid", "wlan-passw") //join infrastructure network with password 79 | // ret = join("wlan-ssid") //join infrastructure network 80 | ret = RedFly.join("wlan-ssid", "wlan-passw", INFRASTRUCTURE); 81 | if(ret) 82 | { 83 | debugoutln("JOIN ERR"); 84 | for(;;); //do nothing forevermore 85 | } 86 | else 87 | { 88 | //set ip config 89 | // ret = RedFly.begin(); //DHCP 90 | // ret = RedFly.begin(1 or 2); //1=DHCP or 2=Auto-IP 91 | // ret = RedFly.begin(ip); 92 | // ret = RedFly.begin(ip, dnsserver); 93 | // ret = RedFly.begin(ip, dnsserver, gateway); 94 | // ret = RedFly.begin(ip, dnsserver, gateway, netmask); 95 | ret = RedFly.begin(ip); 96 | if(ret) 97 | { 98 | debugoutln("BEGIN ERR"); 99 | RedFly.disconnect(); 100 | for(;;); //do nothing forevermore 101 | } 102 | else 103 | { 104 | //receive shield IP in case of DHCP/Auto-IP 105 | RedFly.getlocalip(ip); 106 | 107 | //start server 108 | server.begin(); 109 | 110 | //set other device name 111 | // NBNS.setName("REDFLY"); 112 | // NBNS.setNamePGM(PSTR("REDFLY")); 113 | } 114 | } 115 | } 116 | } 117 | 118 | 119 | void loop() 120 | { 121 | //NBNS service routine 122 | NBNS.service(); 123 | 124 | //listen for incoming clients (HTTP server) 125 | if(server.available()) 126 | { 127 | //an http request ends with a blank line 128 | boolean currentLineIsBlank = true; 129 | while(server.available()) 130 | { 131 | char c = server.read(); 132 | //if you've gotten to the end of the line (received a newline 133 | //character) and the line is blank, the http request has ended, 134 | //so you can send a reply 135 | if(c == '\n' && currentLineIsBlank) 136 | { 137 | //clear input buffer 138 | server.flush(); 139 | 140 | //send standard HTTP 200 header 141 | server.print_P(PSTR("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n")); 142 | 143 | //send some text 144 | server.println_P(PSTR("Hello, World!

")); 145 | 146 | //show IP address of RedFly 147 | server.println_P(PSTR("My IP is: ")); 148 | server.print(ip[0], DEC); server.print("."); 149 | server.print(ip[1], DEC); server.print("."); 150 | server.print(ip[2], DEC); server.print("."); 151 | server.print(ip[3], DEC); 152 | break; 153 | } 154 | if(c == '\n') 155 | { 156 | //you're starting a new line 157 | currentLineIsBlank = true; 158 | } 159 | else if(c != '\r') 160 | { 161 | //you've gotten a character on the current line 162 | currentLineIsBlank = false; 163 | } 164 | } 165 | 166 | //close connection 167 | server.stop(); 168 | } 169 | else if(!server.connected()) //listening port still open? 170 | { 171 | server.stop(); //stop and reset server 172 | server.begin(); //start server 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /RedFly/examples/NTP/NTP.ino: -------------------------------------------------------------------------------- 1 | /* 2 | NTP (Network Time Protocol) Test 3 | 4 | This sketch connects to a NTP server and gets the current time. 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | 11 | byte ip[] = { 192,168, 0, 30 }; //ip from shield (client) 12 | byte netmask[] = { 255,255,255, 0 }; //netmask 13 | byte gateway[] = { 192,168, 0,100 }; //ip from gateway/router 14 | byte dnsserver[] = { 192,168, 0,100 }; //ip from dns server 15 | byte server[] = { 0, 0, 0, 0 }; //{ 188,138,107,156 }; //ip from pool.ntp.org (server) 16 | 17 | #define HOSTNAME "pool.ntp.org" //host 18 | 19 | 20 | //debug output functions (9600 Baud, 8N2) 21 | //Leonardo boards use USB for communication, so we dont need to disable the RedFly 22 | void debugout(char *s) 23 | { 24 | #if defined(__AVR_ATmega32U4__) 25 | Serial.print(s); 26 | #else 27 | RedFly.disable(); 28 | Serial.print(s); 29 | RedFly.enable(); 30 | #endif 31 | } 32 | 33 | void debugoutln(char *s) 34 | { 35 | #if defined(__AVR_ATmega32U4__) 36 | Serial.println(s); 37 | #else 38 | RedFly.disable(); 39 | Serial.println(s); 40 | RedFly.enable(); 41 | #endif 42 | } 43 | 44 | 45 | void setup() 46 | { 47 | uint8_t ret; 48 | 49 | #if defined(__AVR_ATmega32U4__) //Leonardo boards use USB for communication 50 | Serial.begin(9600); //init serial port and set baudrate 51 | while(!Serial); //wait for serial port to connect (needed for Leonardo only) 52 | #endif 53 | 54 | //init the WiFi module on the shield 55 | // ret = RedFly.init(br, pwr) //br=9600|19200|38400|57600|115200|200000|230400, pwr=LOW_POWER|MED_POWER|HIGH_POWER 56 | // ret = RedFly.init(pwr) //9600 baud, pwr=LOW_POWER|MED_POWER|HIGH_POWER 57 | // ret = RedFly.init() //9600 baud, HIGH_POWER 58 | ret = RedFly.init(); 59 | if(ret) 60 | { 61 | debugoutln("INIT ERR"); //there are problems with the communication between the Arduino and the RedFly 62 | } 63 | else 64 | { 65 | //scan for wireless networks (must be run before join command) 66 | RedFly.scan(); 67 | 68 | //join network 69 | // ret = join("wlan-ssid", "wlan-passw", INFRASTRUCTURE or IBSS_JOINER or IBSS_CREATOR, chn, authmode) //join infrastructure or ad-hoc network, or create ad-hoc network 70 | // ret = join("wlan-ssid", "wlan-passw", IBSS_CREATOR, chn) //create ad-hoc network with password, channel 1-14 71 | // ret = join("wlan-ssid", IBSS_CREATOR, chn) //create ad-hoc network, channel 1-14 72 | // ret = join("wlan-ssid", "wlan-passw", INFRASTRUCTURE or IBSS_JOINER) //join infrastructure or ad-hoc network with password 73 | // ret = join("wlan-ssid", INFRASTRUCTURE or IBSS_JOINER) //join infrastructure or ad-hoc network 74 | // ret = join("wlan-ssid", "wlan-passw") //join infrastructure network with password 75 | // ret = join("wlan-ssid") //join infrastructure network 76 | ret = RedFly.join("wlan-ssid", "wlan-passw", INFRASTRUCTURE); 77 | if(ret) 78 | { 79 | debugoutln("JOIN ERR"); 80 | for(;;); //do nothing forevermore 81 | } 82 | else 83 | { 84 | //set ip config 85 | // ret = RedFly.begin(); //DHCP 86 | // ret = RedFly.begin(1 or 2); //1=DHCP or 2=Auto-IP 87 | // ret = RedFly.begin(ip); 88 | // ret = RedFly.begin(ip, dnsserver); 89 | // ret = RedFly.begin(ip, dnsserver, gateway); 90 | // ret = RedFly.begin(ip, dnsserver, gateway, netmask); 91 | ret = RedFly.begin(ip, dnsserver, gateway, netmask); 92 | if(ret) 93 | { 94 | debugoutln("BEGIN ERR"); 95 | RedFly.disconnect(); 96 | for(;;); //do nothing forevermore 97 | } 98 | else 99 | { 100 | if(RedFly.getip(HOSTNAME, server) == 0) //get ip 101 | { 102 | uint32_t time; 103 | time = RedFly.gettime(server); //get time 104 | if(time != 0UL) 105 | { 106 | char tmp[64]; 107 | sprintf_P(tmp, PSTR("Time: %lu sec since 1970"), time); 108 | debugoutln(tmp); 109 | } 110 | else 111 | { 112 | debugoutln("NTP ERR"); 113 | RedFly.disconnect(); 114 | for(;;); //do nothing forevermore 115 | } 116 | } 117 | else 118 | { 119 | debugoutln("DNS ERR"); 120 | RedFly.disconnect(); 121 | for(;;); //do nothing forevermore 122 | } 123 | } 124 | } 125 | } 126 | } 127 | 128 | 129 | void loop() 130 | { 131 | 132 | } 133 | -------------------------------------------------------------------------------- /RedFly/examples/UDP/UDP.ino: -------------------------------------------------------------------------------- 1 | /* 2 | UDP Test 3 | 4 | Test sketch for UDP client/server API. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | byte ip[] = { 192,168, 0, 30 }; //ip from shield (client) 14 | byte serverip[] = { 192,168, 0, 20 }; 15 | 16 | //initialize the libraries 17 | RedFlyClient client(serverip, 1000); 18 | RedFlyServer server(1000); 19 | 20 | 21 | //debug output functions (9600 Baud, 8N2) 22 | //Leonardo boards use USB for communication, so we dont need to disable the RedFly 23 | void debugout(char *s) 24 | { 25 | #if defined(__AVR_ATmega32U4__) 26 | Serial.print(s); 27 | #else 28 | RedFly.disable(); 29 | Serial.print(s); 30 | RedFly.enable(); 31 | #endif 32 | } 33 | 34 | void debugoutln(char *s) 35 | { 36 | #if defined(__AVR_ATmega32U4__) 37 | Serial.println(s); 38 | #else 39 | RedFly.disable(); 40 | Serial.println(s); 41 | RedFly.enable(); 42 | #endif 43 | } 44 | 45 | 46 | void setup() 47 | { 48 | uint8_t ret; 49 | 50 | #if defined(__AVR_ATmega32U4__) //Leonardo boards use USB for communication 51 | Serial.begin(9600); //init serial port and set baudrate 52 | while(!Serial); //wait for serial port to connect (needed for Leonardo only) 53 | #endif 54 | 55 | //init the WiFi module on the shield 56 | // ret = RedFly.init(br, pwr) //br=9600|19200|38400|57600|115200|200000|230400, pwr=LOW_POWER|MED_POWER|HIGH_POWER 57 | // ret = RedFly.init(pwr) //9600 baud, pwr=LOW_POWER|MED_POWER|HIGH_POWER 58 | // ret = RedFly.init() //9600 baud, HIGH_POWER 59 | ret = RedFly.init(); 60 | if(ret) 61 | { 62 | debugoutln("INIT ERR"); //there are problems with the communication between the Arduino and the RedFly 63 | } 64 | else 65 | { 66 | //scan for wireless networks (must be run before join command) 67 | RedFly.scan(); 68 | 69 | //join network 70 | // ret = join("wlan-ssid", "wlan-passw", INFRASTRUCTURE or IBSS_JOINER or IBSS_CREATOR, chn, authmode) //join infrastructure or ad-hoc network, or create ad-hoc network 71 | // ret = join("wlan-ssid", "wlan-passw", IBSS_CREATOR, chn) //create ad-hoc network with password, channel 1-14 72 | // ret = join("wlan-ssid", IBSS_CREATOR, chn) //create ad-hoc network, channel 1-14 73 | // ret = join("wlan-ssid", "wlan-passw", INFRASTRUCTURE or IBSS_JOINER) //join infrastructure or ad-hoc network with password 74 | // ret = join("wlan-ssid", INFRASTRUCTURE or IBSS_JOINER) //join infrastructure or ad-hoc network 75 | // ret = join("wlan-ssid", "wlan-passw") //join infrastructure network with password 76 | // ret = join("wlan-ssid") //join infrastructure network 77 | ret = RedFly.join("wlan-ssid", "wlan-passw", INFRASTRUCTURE); 78 | if(ret) 79 | { 80 | debugoutln("JOIN ERR"); 81 | for(;;); //do nothing forevermore 82 | } 83 | else 84 | { 85 | //set ip config 86 | // ret = RedFly.begin(); //DHCP 87 | // ret = RedFly.begin(1 or 2); //1=DHCP or 2=Auto-IP 88 | // ret = RedFly.begin(ip); 89 | // ret = RedFly.begin(ip, dnsserver); 90 | // ret = RedFly.begin(ip, dnsserver, gateway); 91 | // ret = RedFly.begin(ip, dnsserver, gateway, netmask); 92 | ret = RedFly.begin(ip); 93 | if(ret) 94 | { 95 | debugoutln("BEGIN ERR"); 96 | RedFly.disconnect(); 97 | for(;;); //do nothing forevermore 98 | } 99 | else 100 | { 101 | client.connectUDP(); 102 | client.println_P(PSTR("Hello, World!")); 103 | //client.stop(); 104 | 105 | server.beginUDP(); 106 | } 107 | } 108 | } 109 | } 110 | 111 | 112 | void loop() 113 | { 114 | uint8_t buf[128]; 115 | uint16_t i; 116 | 117 | i = client.available(); 118 | if(i) 119 | { 120 | i = client.read(buf, i); 121 | buf[i] = 0; 122 | debugoutln("Client: "); 123 | debugoutln((char*)buf); 124 | } 125 | 126 | i = server.available(); 127 | if(i) 128 | { 129 | i = server.read(buf, i); 130 | buf[i] = 0; 131 | debugoutln("Server: "); 132 | debugoutln((char*)buf); 133 | } 134 | else if(!server.connected()) //listening port still open? 135 | { 136 | server.stop(); //stop and reset server 137 | server.beginUDP(); //start server 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /RedFly/examples/WLANScan/WLANScan.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WLAN Scanner 3 | 4 | This sketch scans for WLANs using a RedFly-Shield. 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | 11 | //debug output functions (9600 Baud, 8N2) 12 | //Leonardo boards use USB for communication, so we dont need to disable the RedFly 13 | void debugout(char *s) 14 | { 15 | #if defined(__AVR_ATmega32U4__) 16 | Serial.print(s); 17 | #else 18 | RedFly.disable(); 19 | Serial.print(s); 20 | RedFly.enable(); 21 | #endif 22 | } 23 | 24 | void debugoutln(char *s) 25 | { 26 | #if defined(__AVR_ATmega32U4__) 27 | Serial.println(s); 28 | #else 29 | RedFly.disable(); 30 | Serial.println(s); 31 | RedFly.enable(); 32 | #endif 33 | } 34 | 35 | 36 | void setup() 37 | { 38 | uint8_t ret; 39 | 40 | #if defined(__AVR_ATmega32U4__) //Leonardo boards use USB for communication 41 | Serial.begin(9600); //init serial port and set baudrate 42 | while(!Serial); //wait for serial port to connect (needed for Leonardo only) 43 | #endif 44 | 45 | //init the WiFi module on the shield 46 | // ret = RedFly.init(br, pwr) //br=9600|19200|38400|57600|115200|200000|230400, pwr=LOW_POWER|MED_POWER|HIGH_POWER 47 | // ret = RedFly.init(pwr) //9600 baud, pwr=LOW_POWER|MED_POWER|HIGH_POWER 48 | // ret = RedFly.init() //9600 baud, HIGH_POWER 49 | ret = RedFly.init(); 50 | if(ret) 51 | { 52 | debugoutln("INIT ERR"); 53 | for(;;); //do nothing forevermore 54 | } 55 | 56 | //get firmware version 57 | char ver[5+1]; 58 | if(RedFly.getversion(ver) == 0) 59 | { 60 | debugout("FW: "); 61 | debugoutln(ver); 62 | } 63 | 64 | //get WiFi module MAC 65 | uint8_t mac[6]; 66 | if(RedFly.getmac(mac) == 0) 67 | { 68 | char tmp[32]; 69 | sprintf_P(tmp, PSTR("MAC: %x:%x:%x:%x:%x:%x"), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 70 | debugoutln(tmp); 71 | } 72 | 73 | debugoutln("-----------------"); 74 | debugoutln("Start scanning..."); 75 | debugoutln("-----------------"); 76 | } 77 | 78 | 79 | void loop() 80 | { 81 | uint8_t ret, mode, rssi, type, mac[6]; 82 | char buf[64]; 83 | 84 | //scan for wireless networks 85 | buf[0] = 0; 86 | ret = RedFly.scan(buf, &mode, &rssi); 87 | while((ret == 0) && (rssi != 0)) 88 | { 89 | //show mode (0=Open, 1=WPA, 2=WPA2, 3=WEP) and RSSI 90 | debugout(buf); 91 | sprintf_P(buf, PSTR(", mode %i, rssi -%i dBm"), mode, rssi); 92 | debugoutln(buf); 93 | 94 | //get and show type (0=Ad-hoc, 1=Infrastructure) 95 | ret = RedFly.gettype(buf, &type); 96 | if(ret == 0) 97 | { 98 | debugout(buf); 99 | sprintf_P(buf, PSTR(", type %i"), type); 100 | debugoutln(buf); 101 | } 102 | 103 | //get and show BSSID 104 | ret = RedFly.getbssid(buf, mac); 105 | if(ret == 0) 106 | { 107 | debugout(buf); 108 | sprintf_P(buf, PSTR(", bssid %x:%x:%x:%x:%x:%x"), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 109 | debugoutln(buf); 110 | } 111 | 112 | //next scan 113 | buf[0] = 0; 114 | ret = RedFly.nextscan(buf, &mode, &rssi); 115 | } 116 | 117 | //wait 3s 118 | delay(3000); 119 | } 120 | -------------------------------------------------------------------------------- /RedFly/examples/WebClient/WebClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Web Client 3 | 4 | This sketch connects to a website using a RedFly-Shield. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | byte ip[] = { 192,168, 0, 30 }; //ip from shield (client) 13 | byte netmask[] = { 255,255,255, 0 }; //netmask 14 | byte gateway[] = { 192,168, 0,100 }; //ip from gateway/router 15 | byte dnsserver[] = { 192,168, 0,100 }; //ip from dns server 16 | byte server[] = { 0, 0, 0, 0 }; //{ 85, 13,145,242 }; //ip from www.watterott.net (server) 17 | 18 | #define HOSTNAME "www.watterott.net" //host 19 | 20 | //initialize the client library with the ip and port of the server 21 | //that you want to connect to (port 80 is default for HTTP) 22 | RedFlyClient client(server, 80); 23 | 24 | 25 | //debug output functions (9600 Baud, 8N2) 26 | //Leonardo boards use USB for communication, so we dont need to disable the RedFly 27 | void debugout(char *s) 28 | { 29 | #if defined(__AVR_ATmega32U4__) 30 | Serial.print(s); 31 | #else 32 | RedFly.disable(); 33 | Serial.print(s); 34 | RedFly.enable(); 35 | #endif 36 | } 37 | 38 | void debugoutln(char *s) 39 | { 40 | #if defined(__AVR_ATmega32U4__) 41 | Serial.println(s); 42 | #else 43 | RedFly.disable(); 44 | Serial.println(s); 45 | RedFly.enable(); 46 | #endif 47 | } 48 | 49 | 50 | void setup() 51 | { 52 | uint8_t ret; 53 | 54 | #if defined(__AVR_ATmega32U4__) //Leonardo boards use USB for communication 55 | Serial.begin(9600); //init serial port and set baudrate 56 | while(!Serial); //wait for serial port to connect (needed for Leonardo only) 57 | #endif 58 | 59 | //init the WiFi module on the shield 60 | // ret = RedFly.init(br, pwr) //br=9600|19200|38400|57600|115200|200000|230400, pwr=LOW_POWER|MED_POWER|HIGH_POWER 61 | // ret = RedFly.init(pwr) //9600 baud, pwr=LOW_POWER|MED_POWER|HIGH_POWER 62 | // ret = RedFly.init() //9600 baud, HIGH_POWER 63 | ret = RedFly.init(); 64 | if(ret) 65 | { 66 | debugoutln("INIT ERR"); //there are problems with the communication between the Arduino and the RedFly 67 | } 68 | else 69 | { 70 | //scan for wireless networks (must be run before join command) 71 | RedFly.scan(); 72 | 73 | //join network 74 | // ret = join("wlan-ssid", "wlan-passw", INFRASTRUCTURE or IBSS_JOINER or IBSS_CREATOR, chn, authmode) //join infrastructure or ad-hoc network, or create ad-hoc network 75 | // ret = join("wlan-ssid", "wlan-passw", IBSS_CREATOR, chn) //create ad-hoc network with password, channel 1-14 76 | // ret = join("wlan-ssid", IBSS_CREATOR, chn) //create ad-hoc network, channel 1-14 77 | // ret = join("wlan-ssid", "wlan-passw", INFRASTRUCTURE or IBSS_JOINER) //join infrastructure or ad-hoc network with password 78 | // ret = join("wlan-ssid", INFRASTRUCTURE or IBSS_JOINER) //join infrastructure or ad-hoc network 79 | // ret = join("wlan-ssid", "wlan-passw") //join infrastructure network with password 80 | // ret = join("wlan-ssid") //join infrastructure network 81 | ret = RedFly.join("wlan-ssid", "wlan-passw", INFRASTRUCTURE); 82 | if(ret) 83 | { 84 | debugoutln("JOIN ERR"); 85 | for(;;); //do nothing forevermore 86 | } 87 | else 88 | { 89 | //set ip config 90 | // ret = RedFly.begin(); //DHCP 91 | // ret = RedFly.begin(1 or 2); //1=DHCP or 2=Auto-IP 92 | // ret = RedFly.begin(ip); 93 | // ret = RedFly.begin(ip, dnsserver); 94 | // ret = RedFly.begin(ip, dnsserver, gateway); 95 | // ret = RedFly.begin(ip, dnsserver, gateway, netmask); 96 | ret = RedFly.begin(ip, dnsserver, gateway, netmask); 97 | if(ret) 98 | { 99 | debugoutln("BEGIN ERR"); 100 | RedFly.disconnect(); 101 | for(;;); //do nothing forevermore 102 | } 103 | else 104 | { 105 | if(RedFly.getip(HOSTNAME, server) == 0) //get ip 106 | { 107 | if(client.connect(server, 80)) 108 | { 109 | //make a HTTP request 110 | client.print_P(PSTR("GET / HTTP/1.1\r\nHost: "HOSTNAME"\r\n\r\n")); 111 | } 112 | else 113 | { 114 | debugoutln("CLIENT ERR"); 115 | RedFly.disconnect(); 116 | for(;;); //do nothing forevermore 117 | } 118 | } 119 | else 120 | { 121 | debugoutln("DNS ERR"); 122 | RedFly.disconnect(); 123 | for(;;); //do nothing forevermore 124 | } 125 | } 126 | } 127 | } 128 | } 129 | 130 | 131 | char data[1024]; //receive buffer 132 | unsigned int len=0; //receive buffer length 133 | 134 | void loop() 135 | { 136 | int c; 137 | 138 | //if there are incoming bytes available 139 | //from the server then read them 140 | if(client.available()) 141 | { 142 | do 143 | { 144 | c = client.read(); 145 | if((c != -1) && (len < (sizeof(data)-1))) 146 | { 147 | data[len++] = c; 148 | } 149 | }while(c != -1); 150 | } 151 | 152 | //if the server's disconnected, stop the client and print the received data 153 | if(len && !client.connected()) 154 | { 155 | client.stop(); 156 | RedFly.disconnect(); 157 | 158 | data[len] = 0; 159 | debugout(data); 160 | 161 | len = 0; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /RedFly/examples/WebClient_Socket/WebClient_Socket.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Web Client (Socket API) 3 | 4 | This sketch connects to a website using a RedFly-Shield. 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | 11 | byte ip[] = { 192,168, 0, 30 }; //ip from shield (client) 12 | byte netmask[] = { 255,255,255, 0 }; //netmask 13 | byte gateway[] = { 192,168, 0,100 }; //ip from gateway/router 14 | byte dnsserver[] = { 192,168, 0,100 }; //ip from dns server 15 | byte server[] = { 0, 0, 0, 0 }; //{ 85, 13,145,242 }; //ip from www.watterott.net (server) 16 | 17 | #define HOSTNAME "www.watterott.net" //host 18 | 19 | uint8_t http=INVALID_SOCKET; //socket handle 20 | uint16_t http_len=0; //receive len 21 | char http_buf[512]; //receive buffer 22 | 23 | 24 | //debug output functions (9600 Baud, 8N2) 25 | //Leonardo boards use USB for communication, so we dont need to disable the RedFly 26 | void debugout(char *s) 27 | { 28 | #if defined(__AVR_ATmega32U4__) 29 | Serial.print(s); 30 | #else 31 | RedFly.disable(); 32 | Serial.print(s); 33 | RedFly.enable(); 34 | #endif 35 | } 36 | 37 | void debugoutln(char *s) 38 | { 39 | #if defined(__AVR_ATmega32U4__) 40 | Serial.println(s); 41 | #else 42 | RedFly.disable(); 43 | Serial.println(s); 44 | RedFly.enable(); 45 | #endif 46 | } 47 | 48 | 49 | void setup() 50 | { 51 | uint8_t ret; 52 | 53 | #if defined(__AVR_ATmega32U4__) //Leonardo boards use USB for communication 54 | Serial.begin(9600); //init serial port and set baudrate 55 | while(!Serial); //wait for serial port to connect (needed for Leonardo only) 56 | #endif 57 | 58 | //init the WiFi module on the shield 59 | // ret = RedFly.init(br, pwr) //br=9600|19200|38400|57600|115200|200000|230400, pwr=LOW_POWER|MED_POWER|HIGH_POWER 60 | // ret = RedFly.init(pwr) //9600 baud, pwr=LOW_POWER|MED_POWER|HIGH_POWER 61 | // ret = RedFly.init() //9600 baud, HIGH_POWER 62 | ret = RedFly.init(); 63 | if(ret) 64 | { 65 | debugoutln("INIT ERR"); //there are problems with the communication between the Arduino and the RedFly 66 | } 67 | else 68 | { 69 | //scan for wireless networks (must be run before join command) 70 | RedFly.scan(); 71 | 72 | //join network 73 | // ret = join("wlan-ssid", "wlan-passw", INFRASTRUCTURE or IBSS_JOINER or IBSS_CREATOR, chn, authmode) //join infrastructure or ad-hoc network, or create ad-hoc network 74 | // ret = join("wlan-ssid", "wlan-passw", IBSS_CREATOR, chn) //create ad-hoc network with password, channel 1-14 75 | // ret = join("wlan-ssid", IBSS_CREATOR, chn) //create ad-hoc network, channel 1-14 76 | // ret = join("wlan-ssid", "wlan-passw", INFRASTRUCTURE or IBSS_JOINER) //join infrastructure or ad-hoc network with password 77 | // ret = join("wlan-ssid", INFRASTRUCTURE or IBSS_JOINER) //join infrastructure or ad-hoc network 78 | // ret = join("wlan-ssid", "wlan-passw") //join infrastructure network with password 79 | // ret = join("wlan-ssid") //join infrastructure network 80 | ret = RedFly.join("wlan-ssid", "wlan-passw", INFRASTRUCTURE); 81 | if(ret) 82 | { 83 | debugoutln("JOIN ERR"); 84 | for(;;); //do nothing forevermore 85 | } 86 | else 87 | { 88 | //set ip config 89 | // ret = RedFly.begin(); //DHCP 90 | // ret = RedFly.begin(1 or 2); //1=DHCP or 2=Auto-IP 91 | // ret = RedFly.begin(ip); 92 | // ret = RedFly.begin(ip, dnsserver); 93 | // ret = RedFly.begin(ip, dnsserver, gateway); 94 | // ret = RedFly.begin(ip, dnsserver, gateway, netmask); 95 | ret = RedFly.begin(ip, dnsserver, gateway, netmask); 96 | if(ret) 97 | { 98 | debugoutln("BEGIN ERR"); 99 | RedFly.disconnect(); 100 | for(;;); //do nothing forevermore 101 | } 102 | else 103 | { 104 | if(RedFly.getip(HOSTNAME, server) == 0) //get ip 105 | { 106 | http = RedFly.socketConnect(PROTO_TCP, server, 80); //start connection to server on port 80 107 | if(http == 0xFF) 108 | { 109 | debugoutln("SOCKET ERR"); 110 | RedFly.disconnect(); 111 | for(;;); //do nothing forevermore 112 | } 113 | else 114 | { 115 | //send HTTP request 116 | RedFly.socketSendPGM(http, PSTR("GET / HTTP/1.1\r\nHost: "HOSTNAME"\r\n\r\n")); 117 | } 118 | } 119 | else 120 | { 121 | debugoutln("DNS ERR"); 122 | RedFly.disconnect(); 123 | for(;;); //do nothing forevermore 124 | } 125 | } 126 | } 127 | } 128 | } 129 | 130 | 131 | void loop() 132 | { 133 | uint8_t sock, buf[32]; 134 | uint16_t rd, len; 135 | 136 | if(http == INVALID_SOCKET) //no socket open 137 | { 138 | return; 139 | } 140 | 141 | sock = 0xFF; //0xFF = return data from all open sockets 142 | rd = RedFly.socketRead(&sock, &len, buf, sizeof(buf)); 143 | if(sock == http) 144 | { 145 | if((rd != 0) && (rd != 0xFFFF)) 146 | { 147 | if((http_len+rd) > sizeof(http_buf)) 148 | { 149 | rd = sizeof(http_buf)-http_len; 150 | } 151 | memcpy(&http_buf[http_len], buf, rd); 152 | http_len += rd; 153 | } 154 | 155 | if((rd == 0xFFFF) || (len == 0)) //connection closed or all data received 156 | { 157 | //close connection 158 | RedFly.socketClose(sock); 159 | 160 | //show http buffer 161 | http_buf[sizeof(http_buf)-1] = 0; 162 | debugout(http_buf); 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /RedFly/examples/WebServer_Socket/conn_test.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | RedFly Connection Test 4 | 5 | 6 | 44 | 45 | 46 | 47 |

RedFly Connection Test

48 | RedFly URL: 49 | 50 |

51 | 52 |



53 | 54 | Using Yahoo YQL to bypass cross site protection.
55 | Route: HTML document -> Yahoo YQL -> Cross Domain -> Yahoo YQL -> HTML document 56 |
57 | 58 | 59 | -------------------------------------------------------------------------------- /RedFly/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "RedFly", 3 | "version": "1.0.0", 4 | "keywords": "wifi, wlan", 5 | "description": "RedFly-Shield (WiFi/WLAN)", 6 | "include": "RedFly", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "frameworks": "arduino", 13 | "platforms": "atmelavr" 14 | } 15 | -------------------------------------------------------------------------------- /RedFly/library.properties: -------------------------------------------------------------------------------- 1 | name=RedFly 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=RedFly-Shield (WiFi/WLAN) 6 | paragraph=RedFly-Shield (WiFi/WLAN) 7 | category=Communication 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /RotaryEncoder/RotaryEncoder.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Rotary Encoder Lib for Arduino 3 | by Watterott electronic (www.watterott.com) 4 | 5 | reading routine by Peter Dannegger 6 | http://www.mikrocontroller.net/articles/Drehgeber 7 | */ 8 | 9 | #include 10 | #if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) 11 | # include 12 | #endif 13 | #if ARDUINO >= 100 14 | # include "Arduino.h" 15 | #else 16 | # include "WProgram.h" 17 | #endif 18 | #include "digitalWriteFast.h" 19 | #include "RotaryEncoder.h" 20 | 21 | 22 | #define STEPS 4 //1, 2 or 4 steps 23 | 24 | #define RE_SW_PIN 5 25 | #define RE_PHA_PIN 6 26 | #define RE_PHB_PIN 7 27 | 28 | #define RE_SW_READ() digitalReadFast(RE_SW_PIN) 29 | #define RE_PHA_READ() digitalReadFast(RE_PHA_PIN) 30 | #define RE_PHB_READ() digitalReadFast(RE_PHB_PIN) 31 | 32 | 33 | //-------------------- Constructor -------------------- 34 | 35 | 36 | RotaryEncoder::RotaryEncoder(void) 37 | { 38 | return; 39 | } 40 | 41 | 42 | //-------------------- Public -------------------- 43 | 44 | 45 | void RotaryEncoder::init(void) 46 | { 47 | //init pins 48 | pinMode(RE_SW_PIN, INPUT); 49 | digitalWrite(RE_SW_PIN, HIGH); //pull-up 50 | pinMode(RE_PHA_PIN, INPUT); 51 | digitalWrite(RE_PHA_PIN, HIGH); //pull-up 52 | pinMode(RE_PHB_PIN, INPUT); 53 | digitalWrite(RE_PHB_PIN, HIGH); //pull-up 54 | 55 | //init global vars 56 | re_sw = 0; 57 | re_delta = 0; 58 | re_last = 0; 59 | if(RE_PHA_READ()) 60 | { 61 | re_last = 3; 62 | } 63 | if(RE_PHB_READ()) 64 | { 65 | re_last ^= 1; 66 | } 67 | 68 | return; 69 | } 70 | 71 | 72 | void RotaryEncoder::service(void) //called every 1ms 73 | { 74 | int_least8_t re_new, re_diff; 75 | static int_least16_t re_pressed=0; 76 | 77 | re_new = 0; 78 | if(RE_PHA_READ()) 79 | { 80 | re_new = 3; 81 | } 82 | if(RE_PHB_READ()) 83 | { 84 | re_new ^= 1; //convert gray to binary 85 | } 86 | re_diff = re_last-re_new; //difference last - new 87 | if(re_diff & 1) //bit 0 = value (1) 88 | { 89 | re_last = re_new; //store new as next last 90 | re_delta += (re_diff&2)-1; //bit 1 = direction (+/-) 91 | } 92 | 93 | if(RE_SW_READ()) 94 | { 95 | if(re_pressed > 800) //800 ms 96 | { 97 | if(re_sw == 0) 98 | { 99 | re_sw = SW_PRESSEDLONG; 100 | } 101 | } 102 | else if(re_pressed > 80) //80 ms 103 | { 104 | if(re_sw == 0) 105 | { 106 | re_sw = SW_PRESSED; 107 | } 108 | } 109 | re_pressed = 0; 110 | } 111 | else 112 | { 113 | re_pressed++; 114 | } 115 | 116 | return; 117 | } 118 | 119 | 120 | int_least8_t RotaryEncoder::step(void) 121 | { 122 | int_least8_t val; 123 | 124 | cli(); 125 | val = re_delta; 126 | #if STEPS == 1 127 | re_delta = 0; //1step:0 / 2step:val&1 / 4step:val&3 128 | #elif STEPS == 2 129 | re_delta = val&1; //1step:0 / 2step:val&1 / 4step:val&3 130 | #elif STEPS == 4 131 | re_delta = val&3; //1step:0 / 2step:val&1 / 4step:val&3 132 | #endif 133 | sei(); 134 | 135 | #if STEPS == 1 136 | val = val>>0; //1step:val / 2step:val>>1 / 4step:val>>2 137 | #elif STEPS == 2 138 | val = val>>1; //1step:val / 2step:val>>1 / 4step:val>>2 139 | #elif STEPS == 4 140 | val = val>>2; //1step:val / 2step:val>>1 / 4step:val>>2 141 | #endif 142 | 143 | if(val < 0) 144 | { 145 | return +1; 146 | } 147 | else if(val > 0) 148 | { 149 | return -1; 150 | } 151 | 152 | return 0; 153 | } 154 | 155 | 156 | int_least8_t RotaryEncoder::sw(void) 157 | { 158 | int_least8_t val; 159 | 160 | val = re_sw; 161 | re_sw = 0; 162 | 163 | return val; 164 | } 165 | -------------------------------------------------------------------------------- /RotaryEncoder/RotaryEncoder.h: -------------------------------------------------------------------------------- 1 | #ifndef RotaryEncoder_h 2 | #define RotaryEncoder_h 3 | 4 | 5 | #include 6 | 7 | 8 | #define SW_PRESSED 1 9 | #define SW_PRESSEDLONG 2 10 | 11 | 12 | class RotaryEncoder 13 | { 14 | public: 15 | RotaryEncoder(); 16 | 17 | void init(void); 18 | void service(void); 19 | int_least8_t step(void); 20 | int_least8_t sw(void); 21 | 22 | private: 23 | volatile int_least8_t re_sw; 24 | volatile int_least8_t re_delta; 25 | int_least8_t re_last; 26 | }; 27 | 28 | 29 | #endif //RotaryEncoder_h 30 | -------------------------------------------------------------------------------- /RotaryEncoder/examples/Example/Example.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Rotary Encoder Example 3 | 4 | The pins can be changed in the file RotaryEncoder.cpp 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | 11 | RotaryEncoder encoder; 12 | 13 | 14 | ISR(TIMER2_OVF_vect) //timer 2 overflow interrupt 15 | { 16 | TCNT2 -= 250; //1000 Hz 17 | 18 | encoder.service(); 19 | } 20 | 21 | 22 | void setup() 23 | { 24 | //init Serial port 25 | Serial.begin(9600); 26 | while(!Serial); //wait for serial port to connect - needed for Leonardo only 27 | 28 | //init Rotary Encoder 29 | Serial.println("Init Rotary Encoder..."); 30 | encoder.init(); 31 | 32 | //init Timer2 33 | TCCR2B = (1< 6 | #include "GraphicsLib.h" 7 | 8 | 9 | class S65L2F50 : public GraphicsLib 10 | { 11 | public: 12 | S65L2F50(); 13 | 14 | void begin(uint_least8_t clock_div); 15 | void begin(void); 16 | void led(uint_least8_t power); 17 | void invertDisplay(uint_least8_t invert); 18 | void setOrientation(uint_least16_t o); 19 | void setArea(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1); 20 | void drawStart(void); 21 | void draw(uint_least16_t color); 22 | void drawStop(void); 23 | 24 | private: 25 | void reset(void); 26 | void wr_cmd(uint_least8_t cmd); 27 | void wr_dat(uint_least8_t data); 28 | void wr_spi(uint_least8_t data); 29 | }; 30 | 31 | 32 | #endif //S65L2F50_h 33 | -------------------------------------------------------------------------------- /S65L2F50/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "S65L2F50", 3 | "version": "1.0.0", 4 | "keywords": "spi, graphics, display, lcd", 5 | "description": "S65 L2F50 Display (SPI)", 6 | "include": "S65L2F50", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "dependencies": 13 | [ 14 | { 15 | "name": "digitalWriteFast", 16 | "frameworks": "arduino" 17 | }, 18 | { 19 | "name": "GraphicsLib", 20 | "frameworks": "arduino" 21 | } 22 | ], 23 | "frameworks": "arduino", 24 | "platforms": "atmelavr" 25 | } 26 | -------------------------------------------------------------------------------- /S65L2F50/library.properties: -------------------------------------------------------------------------------- 1 | name=S65L2F50 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=S65 L2F50 Display (SPI) 6 | paragraph=S65 L2F50 Display (SPI) 7 | category=Display 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /S65LPH88/S65LPH88.h: -------------------------------------------------------------------------------- 1 | #ifndef S65LPH88_h 2 | #define S65LPH88_h 3 | 4 | 5 | #include 6 | #include "GraphicsLib.h" 7 | 8 | 9 | class S65LPH88 : public GraphicsLib 10 | { 11 | public: 12 | S65LPH88(); 13 | 14 | void begin(uint_least8_t clock_div); 15 | void begin(void); 16 | void led(uint_least8_t power); 17 | void invertDisplay(uint_least8_t invert); 18 | void setOrientation(uint_least16_t o); 19 | void setArea(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1); 20 | void drawStart(void); 21 | void draw(uint_least16_t color); 22 | void drawStop(void); 23 | 24 | private: 25 | void reset(void); 26 | void wr_cmd(uint_least8_t cmd, uint_least16_t param); 27 | void wr_reg(uint_least8_t reg); 28 | void wr_spi(uint_least8_t data); 29 | }; 30 | 31 | 32 | #endif //S65LPH88_h 33 | -------------------------------------------------------------------------------- /S65LPH88/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "S65LPH88", 3 | "version": "1.0.0", 4 | "keywords": "spi, graphics, display, lcd", 5 | "description": "S65 LPH88 Display (SPI)", 6 | "include": "S65LPH88", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "dependencies": 13 | [ 14 | { 15 | "name": "digitalWriteFast", 16 | "frameworks": "arduino" 17 | }, 18 | { 19 | "name": "GraphicsLib", 20 | "frameworks": "arduino" 21 | } 22 | ], 23 | "frameworks": "arduino", 24 | "platforms": "atmelavr" 25 | } 26 | -------------------------------------------------------------------------------- /S65LPH88/library.properties: -------------------------------------------------------------------------------- 1 | name=S65LPH88 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=S65 LPH88 Display (SPI) 6 | paragraph=S65 LPH88 Display (SPI) 7 | category=Display 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /S65LS020/S65LS020.h: -------------------------------------------------------------------------------- 1 | #ifndef S65LS020_h 2 | #define S65LS020_h 3 | 4 | 5 | #include 6 | #include "GraphicsLib.h" 7 | 8 | 9 | class S65LS020 : public GraphicsLib 10 | { 11 | public: 12 | S65LS020(); 13 | 14 | void begin(uint_least8_t clock_div); 15 | void begin(void); 16 | void led(uint_least8_t power); 17 | void invertDisplay(uint_least8_t invert); 18 | void setOrientation(uint_least16_t o); 19 | void setArea(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1); 20 | void drawStart(void); 21 | void draw(uint_least16_t color); 22 | void drawStop(void); 23 | 24 | private: 25 | void reset(void); 26 | void wr_cmd(uint_least8_t cmd, uint_least8_t param); 27 | void wr_spi(uint_least8_t data); 28 | }; 29 | 30 | 31 | #endif //S65LS020_h 32 | -------------------------------------------------------------------------------- /S65LS020/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "S65LS020", 3 | "version": "1.0.0", 4 | "keywords": "spi, graphics, display, lcd", 5 | "description": "S65 LS020 Display (SPI)", 6 | "include": "S65LS020", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "dependencies": 13 | [ 14 | { 15 | "name": "digitalWriteFast", 16 | "frameworks": "arduino" 17 | }, 18 | { 19 | "name": "GraphicsLib", 20 | "frameworks": "arduino" 21 | } 22 | ], 23 | "frameworks": "arduino", 24 | "platforms": "atmelavr" 25 | } 26 | -------------------------------------------------------------------------------- /S65LS020/library.properties: -------------------------------------------------------------------------------- 1 | name=S65LS020 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=S65 LS020 Display (SPI) 6 | paragraph=S65 LS020 Display (SPI) 7 | category=Display 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /SSD1331/SSD1331.h: -------------------------------------------------------------------------------- 1 | #ifndef SSD1331_h 2 | #define SSD1331_h 3 | 4 | 5 | #include 6 | #include "GraphicsLib.h" 7 | 8 | 9 | class SSD1331 : public GraphicsLib 10 | { 11 | public: 12 | SSD1331(); 13 | 14 | void begin(uint_least8_t clock_div); 15 | void begin(void); 16 | void invertDisplay(uint_least8_t invert); 17 | void setOrientation(uint_least16_t o); 18 | void setArea(int_least16_t x0, int_least16_t y0, int_least16_t x1, int_least16_t y1); 19 | void drawStart(void); 20 | void draw(uint_least16_t color); 21 | void drawStop(void); 22 | 23 | private: 24 | void reset(void); 25 | void wr_cmd(uint_least8_t cmd); 26 | void wr_data(uint_least8_t data); 27 | void wr_spi(uint_least8_t data); 28 | }; 29 | 30 | 31 | #endif //SSD1331_h 32 | -------------------------------------------------------------------------------- /SSD1331/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "SSD1331", 3 | "version": "1.0.0", 4 | "keywords": "spi, display, graphics, oled", 5 | "description": "OLED-Display (SSD1331, SPI)", 6 | "include": "SSD1331", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "dependencies": 13 | [ 14 | { 15 | "name": "digitalWriteFast", 16 | "frameworks": "arduino" 17 | }, 18 | { 19 | "name": "GraphicsLib", 20 | "frameworks": "arduino" 21 | } 22 | ], 23 | "frameworks": "arduino", 24 | "platforms": "atmelavr" 25 | } 26 | -------------------------------------------------------------------------------- /SSD1331/library.properties: -------------------------------------------------------------------------------- 1 | name=SSD1331 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=OLED-Display (SSD1331, SPI) 6 | paragraph=OLED-Display (SSD1331, SPI) 7 | category=Display 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /TinyWire/TinyWireM.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | TinyWireM.cpp - a wrapper class for TWI/I2C Master library for the ATtiny on Arduino 3 | 1/21/2011 BroHogan - brohoganx10 at gmail dot com 4 | 5 | **** See TinyWireM.h for Credits and Usage information **** 6 | 7 | This library is free software; you can redistribute it and/or modify it under the 8 | terms of the GNU General Public License as published by the Free Software 9 | Foundation; either version 2.1 of the License, or any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT ANY 12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 13 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 14 | */ 15 | 16 | extern "C" { 17 | #include 18 | #include "USI_TWI_Master.h" 19 | } 20 | 21 | #include "TinyWireM.h" 22 | 23 | 24 | // Initialize Class Variables ////////////////////////////////////////////////// 25 | uint8_t USI_TWI::USI_Buf[USI_BUF_SIZE]; // holds I2C send and receive data 26 | uint8_t USI_TWI::USI_BufIdx = 0; // current number of bytes in the send buff 27 | uint8_t USI_TWI::USI_LastRead = 0; // number of bytes read so far 28 | uint8_t USI_TWI::USI_BytesAvail = 0; // number of bytes requested but not read 29 | 30 | // Constructors //////////////////////////////////////////////////////////////// 31 | 32 | USI_TWI::USI_TWI(){ 33 | } 34 | 35 | // Public Methods ////////////////////////////////////////////////////////////// 36 | 37 | //int USI_TWI::peek(){} 38 | //void USI_TWI::flush(){} 39 | 40 | void USI_TWI::begin(){ // initialize I2C lib 41 | USI_TWI_Master_Initialise(); 42 | } 43 | 44 | void USI_TWI::beginTransmission(uint8_t slaveAddr){ // setup address & write bit 45 | USI_BufIdx = 0; 46 | USI_Buf[USI_BufIdx] = (slaveAddr<= USI_BUF_SIZE) return 0; // dont blow out the buffer 51 | USI_BufIdx++; // inc for next byte in buffer 52 | USI_Buf[USI_BufIdx] = data; 53 | return 1; 54 | } 55 | 56 | uint8_t USI_TWI::endTransmission() { 57 | endTransmission(1); 58 | } 59 | 60 | uint8_t USI_TWI::endTransmission(uint8_t stop){ // actually sends the buffer 61 | bool xferOK = false; 62 | uint8_t errorCode = 0; 63 | xferOK = USI_TWI_Start_Read_Write(USI_Buf,USI_BufIdx+1); // core func that does the work 64 | USI_BufIdx = 0; 65 | if (xferOK) { 66 | if (stop) { 67 | errorCode = USI_TWI_Master_Stop(); 68 | if (errorCode == 0) { 69 | errorCode = USI_TWI_Get_State_Info(); 70 | return errorCode; 71 | } 72 | } 73 | return 0; 74 | } 75 | else { // there was an error 76 | errorCode = USI_TWI_Get_State_Info(); // this function returns the error number 77 | return errorCode; 78 | } 79 | } 80 | 81 | uint8_t USI_TWI::requestFrom(uint8_t slaveAddr, uint8_t numBytes){ // setup for receiving from slave 82 | bool xferOK = false; 83 | uint8_t errorCode = 0; 84 | USI_LastRead = 0; 85 | USI_BytesAvail = numBytes; // save this off in a global 86 | numBytes++; // add extra byte to transmit header 87 | USI_Buf[0] = (slaveAddr< 41 | #include "Arduino.h" 42 | #define USI_SEND 0 // indicates sending to TWI 43 | #define USI_RCVE 1 // indicates receiving from TWI 44 | #define USI_BUF_SIZE 16 // bytes in message buffer 45 | 46 | //class USI_TWI : public Stream 47 | class USI_TWI 48 | { 49 | private: 50 | static uint8_t USI_Buf[]; // holds I2C send and receive data 51 | static uint8_t USI_BufIdx; // current number of bytes in the send buff 52 | static uint8_t USI_LastRead; // number of bytes read so far 53 | static uint8_t USI_BytesAvail; // number of bytes requested but not read 54 | 55 | public: 56 | USI_TWI(); 57 | void begin(); 58 | void beginTransmission(uint8_t); 59 | size_t write(uint8_t); 60 | inline size_t write(uint8_t* d, uint8_t n) { uint16_t i; for (i = 0; i < n; i++) write(d[i]); return (size_t)n; } 61 | inline size_t write(unsigned long n) { return write((uint8_t)n); } 62 | inline size_t write(long n) { return write((uint8_t)n); } 63 | inline size_t write(unsigned int n) { return write((uint8_t)n); } 64 | inline size_t write(int n) { return write((uint8_t)n); } 65 | void send(uint8_t b) { write(b); } 66 | void send(uint8_t *d, uint8_t n) { write(d, n); } 67 | void send(int n) { write((uint8_t)n); } 68 | uint8_t endTransmission(); 69 | uint8_t endTransmission(uint8_t); 70 | uint8_t requestFrom(uint8_t, uint8_t); 71 | int read(); 72 | int available(); 73 | int peek(void); 74 | void flush(void); 75 | uint8_t receive(void) { 76 | int c = read(); 77 | if (c < 0) return 0; 78 | return c; 79 | } 80 | }; 81 | 82 | extern USI_TWI TinyWireM; 83 | 84 | #endif //TinyWireM_h 85 | -------------------------------------------------------------------------------- /TinyWire/TinyWireS.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | TinyWireS.cpp - a wrapper class for Don Blake's usiTwiSlave routines. 3 | Provides TWI/I2C Slave functionality on ATtiny processers in Arduino environment. 4 | 1/23/2011 BroHogan - brohoganx10 at gmail dot com 5 | 6 | **** See TinyWireS.h for Credits and Usage information **** 7 | 8 | This library is free software; you can redistribute it and/or modify it under the 9 | terms of the GNU General Public License as published by the Free Software 10 | Foundation; either version 2.1 of the License, or any later version. 11 | This program is distributed in the hope that it will be useful, but WITHOUT ANY 12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 13 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 14 | */ 15 | 16 | extern "C" { 17 | #include 18 | #include "USI_TWI_Slave.h" 19 | #include 20 | } 21 | 22 | #include "TinyWireS.h" 23 | #include "Arduino.h" 24 | 25 | // Constructors //////////////////////////////////////////////////////////////// 26 | 27 | USI_TWI_S::USI_TWI_S(){ 28 | } 29 | 30 | 31 | // Public Methods ////////////////////////////////////////////////////////////// 32 | 33 | void USI_TWI_S::begin(uint8_t slaveAddr){ // initialize I2C lib 34 | usiTwiSlaveInit(slaveAddr); 35 | } 36 | 37 | void USI_TWI_S::send(uint8_t data){ // send it back to master 38 | usiTwiTransmitByte(data); 39 | } 40 | 41 | uint8_t USI_TWI_S::available(){ // the bytes available that haven't been read yet 42 | return usiTwiAmountDataInReceiveBuffer(); 43 | //return usiTwiDataInReceiveBuffer(); // This is wrong as far as the Wire API is concerned since it returns boolean and not amount 44 | } 45 | 46 | uint8_t USI_TWI_S::receive(){ // returns the bytes received one at a time 47 | return usiTwiReceiveByte(); 48 | } 49 | 50 | // sets function called on slave write 51 | void USI_TWI_S::onReceive( void (*function)(uint8_t) ) 52 | { 53 | usi_onReceiverPtr = function; 54 | } 55 | 56 | // sets function called on slave read 57 | void USI_TWI_S::onRequest( void (*function)(void) ) 58 | { 59 | usi_onRequestPtr = function; 60 | } 61 | 62 | void TinyWireS_stop_check() 63 | { 64 | if (!usi_onReceiverPtr) 65 | { 66 | // no onReceive callback, nothing to do... 67 | return; 68 | } 69 | if (!(USISR & ( 1 << USIPF ))) 70 | { 71 | // Stop not detected 72 | return; 73 | } 74 | uint8_t amount = usiTwiAmountDataInReceiveBuffer(); 75 | if (amount == 0) 76 | { 77 | // no data in buffer 78 | return; 79 | } 80 | usi_onReceiverPtr(amount); 81 | } 82 | 83 | // Implement a delay loop that checks for the stop bit (basically direct copy of the stock arduino implementation from wiring.c) 84 | void tws_delay(unsigned long ms) 85 | { 86 | uint16_t start = (uint16_t)micros(); 87 | while (ms > 0) 88 | { 89 | TinyWireS_stop_check(); 90 | if (((uint16_t)micros() - start) >= 1000) 91 | { 92 | ms--; 93 | start += 1000; 94 | } 95 | } 96 | } 97 | 98 | // Preinstantiate Objects ////////////////////////////////////////////////////// 99 | 100 | USI_TWI_S TinyWireS = USI_TWI_S(); 101 | 102 | -------------------------------------------------------------------------------- /TinyWire/TinyWireS.h: -------------------------------------------------------------------------------- 1 | /* 2 | TinyWireS.h - a wrapper class for Don Blake's usiTwiSlave routines. 3 | Provides TWI/I2C Slave functionality on ATtiny processers in Arduino environment. 4 | 1/23/2011 BroHogan - brohoganx10 at gmail dot com 5 | 6 | Major credit and thanks to Don Blake for his usiTwiSlave code which makes this possible 7 | http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=51467&start=all&postdays=0&postorder=asc 8 | (Changed #define USI_START_COND_INT USISIF (was USICIF) in usiTwiSlave.h) 9 | 10 | NOTE! - It's very important to use pullups on the SDA & SCL lines! More so than with the Wire lib. 11 | Current Rx & Tx buffers set at 32 bytes - see usiTwiSlave.h 12 | 13 | USAGE is modeled after the standard Wire library . . . 14 | Put in setup(): 15 | TinyWireS.begin(I2C_SLAVE_ADDR); // initialize I2C lib & setup slave's address (7 bit - same as Wire) 16 | 17 | To Receive: 18 | someByte = TinyWireS.available(){ // returns the number of bytes in the received buffer 19 | someByte = TinyWireS.receive(){ // returns the next byte in the received buffer 20 | 21 | To Send: 22 | TinyWireS.send(uint8_t data){ // sends a requested byte to master 23 | 24 | TODO: (by others!) 25 | - onReceive and onRequest handlers are not implimented. 26 | - merge this class with TinyWireM for master & slave support in one library 27 | 28 | This library is free software; you can redistribute it and/or modify it under the 29 | terms of the GNU General Public License as published by the Free Software 30 | Foundation; either version 2.1 of the License, or any later version. 31 | This program is distributed in the hope that it will be useful, but WITHOUT ANY 32 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 33 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 34 | */ 35 | 36 | #ifndef TinyWireS_h 37 | #define TinyWireS_h 38 | 39 | #include 40 | 41 | 42 | class USI_TWI_S 43 | { 44 | private: 45 | //static uint8_t USI_BytesAvail; 46 | 47 | public: 48 | USI_TWI_S(); 49 | void begin(uint8_t I2C_SLAVE_ADDR); 50 | void send(uint8_t data); 51 | uint8_t available(); 52 | uint8_t receive(); 53 | void onReceive( void (*)(uint8_t) ); 54 | void onRequest( void (*)(void) ); 55 | }; 56 | 57 | void TinyWireS_stop_check(); 58 | // Implement a delay loop that checks for the stop bit (basically direct copy of the stock arduino implementation from wiring.c) 59 | void tws_delay(unsigned long); 60 | 61 | extern USI_TWI_S TinyWireS; 62 | 63 | #endif //TinyWireSlave_h 64 | 65 | -------------------------------------------------------------------------------- /TinyWire/USI_TWI_Master.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * 3 | * 4 | * File USI_TWI_Master.h compiled with gcc 5 | * Date Friday, 10/31/08 Boo! 6 | * Updated by jkl 7 | * 8 | * 9 | * Supported devices : All device with USI module can be used. 10 | * The example is written for the ATtiny2313 11 | * 12 | * AppNote : AVR310 - Using the USI module as a TWI Master 13 | * 14 | * This is modified to just do I2C communication on ATtiny2313 running at 15 | * 1MHz. Fast mode is probably possible, but would need a faster clock 16 | * and has not been tested. 17 | * 18 | * 12/15/08 Added declaration of USI_TWI_Start_Memory_Read -jkl 19 | ****************************************************************************/ 20 | 21 | #ifndef _USI_TWI_MASTER_H_ 22 | #define _USI_TWI_MASTER_H_ 23 | 24 | //********** Defines **********// 25 | 26 | // For use with _delay_us() 27 | #define T2_TWI 5 // >4,7us 28 | #define T4_TWI 4 // >4,0us 29 | 30 | // Defines error code generating 31 | //#define PARAM_VERIFICATION 32 | //#define NOISE_TESTING 33 | #define SIGNAL_VERIFY // This should probably be on always. 34 | 35 | /**************************************************************************** 36 | Bit and byte definitions 37 | ****************************************************************************/ 38 | #define TWI_READ_BIT 0 // Bit position for R/W bit in "address byte". 39 | #define TWI_ADR_BITS 1 // Bit position for LSB of the slave address bits in the init byte. 40 | #define TWI_NACK_BIT 0 // Bit position for (N)ACK bit. 41 | 42 | // Note these have been renumbered from the Atmel Apps Note. Most likely errors are now 43 | // lowest numbers so they're easily recognized as LED flashes. 44 | #define USI_TWI_NO_DATA 0x08 // Transmission buffer is empty 45 | #define USI_TWI_DATA_OUT_OF_BOUND 0x09 // Transmission buffer is outside SRAM space 46 | #define USI_TWI_UE_START_CON 0x07 // Unexpected Start Condition 47 | #define USI_TWI_UE_STOP_CON 0x06 // Unexpected Stop Condition 48 | #define USI_TWI_UE_DATA_COL 0x05 // Unexpected Data Collision (arbitration) 49 | #define USI_TWI_NO_ACK_ON_DATA 0x02 // The slave did not acknowledge all data 50 | #define USI_TWI_NO_ACK_ON_ADDRESS 0x01 // The slave did not acknowledge the address 51 | #define USI_TWI_MISSING_START_CON 0x03 // Generated Start Condition not detected on bus 52 | #define USI_TWI_MISSING_STOP_CON 0x04 // Generated Stop Condition not detected on bus 53 | #define USI_TWI_BAD_MEM_READ 0x0A // Error during external memory read 54 | 55 | // Device dependant defines ADDED BACK IN FROM ORIGINAL ATMEL .H 56 | 57 | #if defined(__AVR_AT90Mega169__) | defined(__AVR_ATmega169__) | \ 58 | defined(__AVR_AT90Mega165__) | defined(__AVR_ATmega165__) | \ 59 | defined(__AVR_ATmega325__) | defined(__AVR_ATmega3250__) | \ 60 | defined(__AVR_ATmega645__) | defined(__AVR_ATmega6450__) | \ 61 | defined(__AVR_ATmega329__) | defined(__AVR_ATmega3290__) | \ 62 | defined(__AVR_ATmega649__) | defined(__AVR_ATmega6490__) 63 | #define DDR_USI DDRE 64 | #define PORT_USI PORTE 65 | #define PIN_USI PINE 66 | #define PORT_USI_SDA PORTE5 67 | #define PORT_USI_SCL PORTE4 68 | #define PIN_USI_SDA PINE5 69 | #define PIN_USI_SCL PINE4 70 | #endif 71 | 72 | #if defined(__AVR_ATtiny25__) | defined(__AVR_ATtiny45__) | defined(__AVR_ATtiny85__) | \ 73 | defined(__AVR_AT90Tiny26__) | defined(__AVR_ATtiny26__) 74 | #define DDR_USI DDRB 75 | #define PORT_USI PORTB 76 | #define PIN_USI PINB 77 | #define PORT_USI_SDA PORTB0 78 | #define PORT_USI_SCL PORTB2 79 | #define PIN_USI_SDA PINB0 80 | #define PIN_USI_SCL PINB2 81 | #endif 82 | 83 | #if defined(__AVR_AT90Tiny2313__) | defined(__AVR_ATtiny2313__) 84 | #define DDR_USI DDRB 85 | #define PORT_USI PORTB 86 | #define PIN_USI PINB 87 | #define PORT_USI_SDA PORTB5 88 | #define PORT_USI_SCL PORTB7 89 | #define PIN_USI_SDA PINB5 90 | #define PIN_USI_SCL PINB7 91 | #endif 92 | 93 | /* From the original .h 94 | // Device dependant defines - These for ATtiny2313. // CHANGED FOR ATtiny85 95 | 96 | #define DDR_USI DDRB 97 | #define PORT_USI PORTB 98 | #define PIN_USI PINB 99 | #define PORT_USI_SDA PORTB0 // was PORTB5 - N/U 100 | #define PORT_USI_SCL PORTB2 // was PORTB7 - N/U 101 | #define PIN_USI_SDA PINB0 // was PINB5 102 | #define PIN_USI_SCL PINB2 // was PINB7 103 | */ 104 | 105 | // General defines 106 | #define TRUE 1 107 | #define FALSE 0 108 | 109 | //********** Prototypes **********// 110 | 111 | void USI_TWI_Master_Initialise( void ); 112 | unsigned char USI_TWI_Get_State_Info( void ); 113 | unsigned char USI_TWI_Start_Random_Read( unsigned char * , unsigned char ); 114 | unsigned char USI_TWI_Start_Read_Write( unsigned char * , unsigned char ); 115 | unsigned char USI_TWI_Start_Transceiver_With_Data( unsigned char *msg, unsigned char msgSize); 116 | unsigned char USI_TWI_Master_Transfer( unsigned char temp ); 117 | unsigned char USI_TWI_Master_Start( void ); 118 | unsigned char USI_TWI_Master_Stop( void ); 119 | 120 | 121 | #endif // ifndef _USI_TWI_MASTER_H_ 122 | -------------------------------------------------------------------------------- /TinyWire/USI_TWI_Slave.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | 3 | Header file for the USI TWI Slave driver. 4 | 5 | Created by Donald R. Blake 6 | donblake at worldnet.att.net 7 | 8 | --------------------------------------------------------------------------------- 9 | 10 | Created from Atmel source files for Application Note AVR312: Using the USI Module 11 | as an I2C slave. 12 | 13 | This program is free software; you can redistribute it and/or modify it under the 14 | terms of the GNU General Public License as published by the Free Software 15 | Foundation; either version 2 of the License, or (at your option) any later 16 | version. 17 | 18 | This program is distributed in the hope that it will be useful, but WITHOUT ANY 19 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 20 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 21 | 22 | --------------------------------------------------------------------------------- 23 | 24 | Change Activity: 25 | 26 | Date Description 27 | ------ ------------- 28 | 15 Mar 2007 Created. 29 | 30 | ********************************************************************************/ 31 | 32 | 33 | 34 | #ifndef _USI_TWI_SLAVE_H_ 35 | #define _USI_TWI_SLAVE_H_ 36 | 37 | 38 | /******************************************************************************** 39 | 40 | prototypes 41 | 42 | ********************************************************************************/ 43 | 44 | void usiTwiSlaveInit( uint8_t ); 45 | void usiTwiTransmitByte( uint8_t ); 46 | uint8_t usiTwiReceiveByte( void ); 47 | uint8_t usiTwiDataInReceiveBuffer( void ); 48 | void (*_onTwiDataRequest)(void); 49 | uint8_t usiTwiDataInTransmitBuffer(void); 50 | uint8_t usiTwiAmountDataInReceiveBuffer(void); 51 | // on_XXX handler pointers 52 | void (*usi_onRequestPtr)(void); 53 | void (*usi_onReceiverPtr)(uint8_t); 54 | 55 | 56 | /******************************************************************************** 57 | 58 | driver buffer definitions 59 | 60 | ********************************************************************************/ 61 | 62 | // permitted RX buffer sizes: 1, 2, 4, 8, 16, 32, 64, 128 or 256 63 | 64 | #define TWI_RX_BUFFER_SIZE ( 32 ) 65 | #define TWI_RX_BUFFER_MASK ( TWI_RX_BUFFER_SIZE - 1 ) 66 | 67 | #if ( TWI_RX_BUFFER_SIZE & TWI_RX_BUFFER_MASK ) 68 | # error TWI RX buffer size is not a power of 2 69 | #endif 70 | 71 | // permitted TX buffer sizes: 1, 2, 4, 8, 16, 32, 64, 128 or 256 72 | 73 | #define TWI_TX_BUFFER_SIZE ( 32 ) 74 | #define TWI_TX_BUFFER_MASK ( TWI_TX_BUFFER_SIZE - 1 ) 75 | 76 | #if ( TWI_TX_BUFFER_SIZE & TWI_TX_BUFFER_MASK ) 77 | # error TWI TX buffer size is not a power of 2 78 | #endif 79 | 80 | 81 | 82 | #endif // ifndef _USI_TWI_SLAVE_H_ 83 | -------------------------------------------------------------------------------- /TinyWire/examples/Tiny85_I2C_Slave/Tiny85_I2C_Slave.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * Example sketch for writing to and reading from a slave in transactional manner 3 | * 4 | * NOTE: You must not use delay() or I2C communications will fail, use tws_delay() instead (or preferably some smarter timing system) 5 | * 6 | * On write the first byte received is considered the register addres to modify/read 7 | * On each byte sent or read the register address is incremented (and it will loop back to 0) 8 | * 9 | * You can try this with the Arduino I2C REPL sketch at https://github.com/rambo/I2C/blob/master/examples/i2crepl/i2crepl.ino 10 | * If you have bus-pirate remember that the older revisions do not like the slave streching the clock, this leads to all sorts of weird behaviour 11 | * 12 | * To read third value (register number 2 since counting starts at 0) send "[ 8 2 [ 9 r ]", value read should be 0xBE 13 | * If you then send "[ 9 r r r ]" you should get 0xEF 0xDE 0xAD as response (demonstrating the register counter looping back to zero) 14 | * 15 | * You need to have at least 8MHz clock on the ATTiny for this to work (and in fact I have so far tested it only on ATTiny85 @8MHz using internal oscillator) 16 | * Remember to "Burn bootloader" to make sure your chip is in correct mode 17 | */ 18 | 19 | 20 | /** 21 | * Pin notes by Suovula, see also http://hlt.media.mit.edu/?p=1229 22 | * 23 | * DIP and SOIC have same pinout, however the SOIC chips are much cheaper, especially if you buy more than 5 at a time 24 | * For nice breakout boards see https://github.com/rambo/attiny_boards 25 | * 26 | * Basically the arduino pin numbers map directly to the PORTB bit numbers. 27 | * 28 | // I2C 29 | arduino pin 0 = not(OC1A) = PORTB <- _BV(0) = SOIC pin 5 (I2C SDA, PWM) 30 | arduino pin 2 = = PORTB <- _BV(2) = SOIC pin 7 (I2C SCL, Analog 1) 31 | // Timer1 -> PWM 32 | arduino pin 1 = OC1A = PORTB <- _BV(1) = SOIC pin 6 (PWM) 33 | arduino pin 3 = not(OC1B) = PORTB <- _BV(3) = SOIC pin 2 (Analog 3) 34 | arduino pin 4 = OC1B = PORTB <- _BV(4) = SOIC pin 3 (Analog 2) 35 | */ 36 | #define I2C_SLAVE_ADDRESS 0x4 // the 7-bit address (remember to change this when adapting this example) 37 | #include 38 | // The default buffer size, Can't recall the scope of defines right now 39 | #ifndef TWI_RX_BUFFER_SIZE 40 | #define TWI_RX_BUFFER_SIZE ( 16 ) 41 | #endif 42 | 43 | 44 | volatile uint8_t i2c_regs[] = 45 | { 46 | 0xDE, 47 | 0xAD, 48 | 0xBE, 49 | 0xEF, 50 | }; 51 | // Tracks the current register pointer position 52 | volatile byte reg_position; 53 | 54 | /** 55 | * This is called for each read request we receive, never put more than one byte of data (with TinyWireS.send) to the 56 | * send-buffer when using this callback 57 | */ 58 | void requestEvent() 59 | { 60 | TinyWireS.send(i2c_regs[reg_position]); 61 | // Increment the reg position on each read, and loop back to zero 62 | reg_position = (reg_position+1) % sizeof(i2c_regs); 63 | } 64 | 65 | // TODO: Either update this to use something smarter for timing or remove it alltogether 66 | void blinkn(uint8_t blinks) 67 | { 68 | digitalWrite(3, HIGH); 69 | while(blinks--) 70 | { 71 | digitalWrite(3, LOW); 72 | tws_delay(50); 73 | digitalWrite(3, HIGH); 74 | tws_delay(100); 75 | } 76 | } 77 | 78 | /** 79 | * The I2C data received -handler 80 | * 81 | * This needs to complete before the next incoming transaction (start, data, restart/stop) on the bus does 82 | * so be quick, set flags for long running tasks to be called from the mainloop instead of running them directly, 83 | */ 84 | void receiveEvent(uint8_t howMany) 85 | { 86 | if (howMany < 1) 87 | { 88 | // Sanity-check 89 | return; 90 | } 91 | if (howMany > TWI_RX_BUFFER_SIZE) 92 | { 93 | // Also insane number 94 | return; 95 | } 96 | 97 | reg_position = TinyWireS.receive(); 98 | howMany--; 99 | if (!howMany) 100 | { 101 | // This write was only to set the buffer for next read 102 | return; 103 | } 104 | while(howMany--) 105 | { 106 | i2c_regs[reg_position%sizeof(i2c_regs)] = TinyWireS.receive(); 107 | reg_position++; 108 | } 109 | } 110 | 111 | 112 | void setup() 113 | { 114 | // TODO: Tri-state this and wait for input voltage to stabilize 115 | pinMode(3, OUTPUT); // OC1B-, Arduino pin 3, ADC 116 | digitalWrite(3, LOW); // Note that this makes the led turn on, it's wire this way to allow for the voltage sensing above. 117 | 118 | pinMode(1, OUTPUT); // OC1A, also The only HW-PWM -pin supported by the tiny core analogWrite 119 | 120 | /** 121 | * Reminder: taking care of pull-ups is the masters job 122 | */ 123 | 124 | TinyWireS.begin(I2C_SLAVE_ADDRESS); 125 | TinyWireS.onReceive(receiveEvent); 126 | TinyWireS.onRequest(requestEvent); 127 | 128 | 129 | // Whatever other setup routines ? 130 | 131 | digitalWrite(3, HIGH); 132 | } 133 | 134 | void loop() 135 | { 136 | /** 137 | * This is the only way we can detect stop condition (http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=984716&sid=82e9dc7299a8243b86cf7969dd41b5b5#984716) 138 | * it needs to be called in a very tight loop in order not to miss any (REMINDER: Do *not* use delay() anywhere, use tws_delay() instead). 139 | * It will call the function registered via TinyWireS.onReceive(); if there is data in the buffer on stop. 140 | */ 141 | TinyWireS_stop_check(); 142 | } 143 | -------------------------------------------------------------------------------- /TinyWire/examples/Tiny85_Temp/Tiny85_Temp.ino: -------------------------------------------------------------------------------- 1 | /* ATtiny85 as an I2C Master Ex1 BroHogan 1/21/11 2 | * I2C master reading DS1621 temperature sensor. (display with leds) 3 | * SETUP: 4 | * ATtiny Pin 1 = (RESET) N/U ATtiny Pin 2 = (D3) LED3 5 | * ATtiny Pin 3 = (D4) to LED1 ATtiny Pin 4 = GND 6 | * ATtiny Pin 5 = SDA on DS1621 ATtiny Pin 6 = (D1) to LED2 7 | * ATtiny Pin 7 = SCK on DS1621 ATtiny Pin 8 = VCC (2.7-5.5V) 8 | * NOTE! - It's very important to use pullups on the SDA & SCL lines! 9 | * DS1621 wired per data sheet. This ex assumes A0-A2 are set LOW for an addeess of 0x48 10 | * TinyWireM USAGE & CREDITS: - see TinyWireM.h 11 | * NOTES: 12 | * The ATtiny85 + DS1621 draws 1.7mA @5V when leds are not on and not reading temp. 13 | * Using sleep mode, they draw .2 @5V @ idle - see http://brownsofa.org/blog/archives/261 14 | */ 15 | 16 | #include // I2C Master lib for ATTinys which use USI 17 | 18 | #define DS1621_ADDR 0x48 // 7 bit I2C address for DS1621 temperature sensor 19 | #define LED1_PIN 4 // ATtiny Pin 3 20 | #define LED2_PIN 1 // ATtiny Pin 6 21 | #define LED3_PIN 3 // ATtiny Pin 2 22 | 23 | int tempC = 0; // holds temp in C 24 | int tempF = 0; // holds temp in F 25 | 26 | 27 | void setup(){ 28 | pinMode(LED1_PIN,OUTPUT); 29 | pinMode(LED2_PIN,OUTPUT); 30 | pinMode(LED3_PIN,OUTPUT); 31 | Blink(LED1_PIN,2); // show it's alive 32 | TinyWireM.begin(); // initialize I2C lib 33 | Init_Temp(); // Setup DS1621 34 | delay (3000); 35 | } 36 | 37 | 38 | void loop(){ 39 | Get_Temp(); 40 | Blink(LED1_PIN,tempC/10); // blink 10's of temperature on LED 1 41 | delay (1000); 42 | Blink(LED2_PIN,tempC%10); // blink 1's of temperature on LED 2 43 | delay (4000); // wait a few sec before next reading 44 | } 45 | 46 | 47 | void Init_Temp(){ // Setup the DS1621 for one-shot mode 48 | TinyWireM.beginTransmission(DS1621_ADDR); 49 | TinyWireM.send(0xAC); // Access Command Register 50 | TinyWireM.send(B00000001); // Using one-shot mode for battery savings 51 | //TinyWireM.send(B00000000); // if setting continious mode for fast reads 52 | TinyWireM.endTransmission(); // Send to the slave 53 | } 54 | 55 | 56 | void Get_Temp(){ // Get the temperature from a DS1621 57 | TinyWireM.beginTransmission(DS1621_ADDR); 58 | TinyWireM.send(0xEE); // if one-shot, start conversions now 59 | TinyWireM.endTransmission(); // Send 1 byte to the slave 60 | delay(750); // if one-shot, must wait ~750 ms for conversion 61 | TinyWireM.beginTransmission(DS1621_ADDR); 62 | TinyWireM.send(0xAA); // read temperature (for either mode) 63 | TinyWireM.endTransmission(); // Send 1 byte to the slave 64 | TinyWireM.requestFrom(DS1621_ADDR,1); // Request 1 byte from slave 65 | tempC = TinyWireM.receive(); // get the temperature 66 | tempF = tempC * 9 / 5 + 32; // convert to Fahrenheit 67 | } 68 | 69 | 70 | void Blink(byte led, byte times){ // poor man's GUI 71 | for (byte i=0; i< times; i++){ 72 | digitalWrite(led,HIGH); 73 | delay (400); 74 | digitalWrite(led,LOW); 75 | delay (175); 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /TinyWire/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TinyWire", 3 | "version": "1.0.0", 4 | "keywords": "i2c, twowire", 5 | "description": "I2C library for ATtiny", 6 | "include": "TinyWire", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "frameworks": "arduino", 13 | "platforms": "atmelavr" 14 | } 15 | -------------------------------------------------------------------------------- /TinyWire/library.properties: -------------------------------------------------------------------------------- 1 | name=TinyWire 2 | version=1.0.0 3 | author=Bro Hogan, rambo, svoisen 4 | maintainer=Watterott 5 | sentence=I2C library for ATtiny 6 | paragraph=I2C library for ATtiny 7 | category=Communication 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=avr 10 | -------------------------------------------------------------------------------- /TinyWire/readme.txt: -------------------------------------------------------------------------------- 1 | # Arduino TinyWire Library from [sudar](https://github.com/sudar/TinyWire) 2 | 3 | TinyWire is an Arduino library, that provides I2C support for ATtiny micro controllers. 4 | 5 | ATtiny micro controllers don't have built in support for I2C or SPI, instead they have only a Universal Serial Interface (USI). This library uses that to provide I2C support for ATtiny micro controllers. 6 | 7 | ## Installation 8 | 9 | To install the library, download or checkout the source code and place it inside your Arduino's libraries folder. 10 | 11 | Check out the examples inside the `/examples` directory to find out how to use the library. 12 | 13 | ## Credits 14 | 15 | This library was originally written by [Bro Hogan](http://www.arduino.cc/playground/Code/USIi2c) with contributions from [rambo](https://github.com/rambo/TinyWire) and [svoisen](https://github.com/svoisen/TinyWire) 16 | -------------------------------------------------------------------------------- /digitalWriteFast/examples/Example/Example.ino: -------------------------------------------------------------------------------- 1 | /* 2 | digitalWriteFast Example 3 | For boards with AVR microcontrollers (Arduino Uno, Leonardo, Mega). 4 | 5 | Note, the pin parameter has to be a constant. 6 | */ 7 | 8 | #include 9 | 10 | 11 | #define PIN 10 12 | 13 | 14 | void setup() 15 | { 16 | volatile byte pin; 17 | 18 | //set pin mode for pin PIN 19 | pinModeFast(PIN, INPUT); 20 | pinModeFast(PIN, OUTPUT); 21 | 22 | //set pin state for pin PIN 23 | digitalWriteFast(PIN, LOW); 24 | digitalWriteFast(PIN, HIGH); 25 | 26 | //get pin state of pin PIN 27 | pin = digitalReadFast(PIN); //save a proper high/low value 28 | 29 | //demonstrate optimization of tests 30 | if(digitalReadFast(PIN) == HIGH) 31 | { 32 | digitalWriteFast(PIN, LOW); 33 | } 34 | if(digitalReadFast(PIN) == LOW) 35 | { 36 | digitalWriteFast(PIN, HIGH); 37 | } 38 | } 39 | 40 | 41 | void loop() 42 | { 43 | //do nothing 44 | } 45 | -------------------------------------------------------------------------------- /digitalWriteFast/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "digitalWriteFast", 3 | "version": "1.0.0", 4 | "keywords": "io, pin", 5 | "description": "Fast pin access for AVR microcontrollers", 6 | "include": "digitalWriteFast", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "frameworks": "arduino", 13 | "platforms": "atmelavr" 14 | } 15 | -------------------------------------------------------------------------------- /digitalWriteFast/library.properties: -------------------------------------------------------------------------------- 1 | name=digitalWriteFast 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=Fast pin access for AVR microcontrollers 6 | paragraph=Fast pin access for AVR microcontrollers 7 | category=Other 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | License Agreement 2 | 3 | Copyright (c) 2011-2020 Watterott electronic (www.watterott.com) 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, 7 | are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, this 13 | list of conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holders nor the names of its contributors 17 | may be used to endorse or promote products derived from this software without 18 | specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | 32 | 33 | 34 | Third party libraries/software 35 | ------------------------------ 36 | Each package has its own copyright and license agreement, and it is your responsibility to comply with the terms of those agreements. 37 | * ArdOSC - https://github.com/recotana/ArdOSC 38 | * light_ws2812 - https://github.com/cpldcpu/light_ws2812 39 | * MCP2515 - https://github.com/franksmicro/Arduino/tree/master/libraries/MCP2515 40 | * TinyWire - https://github.com/sudar/TinyWire 41 | -------------------------------------------------------------------------------- /light_WS2812/WS2812.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * light weight WS2812 lib V2.1 - Arduino support 3 | * 4 | * Controls WS2811/WS2812/WS2812B RGB-LEDs 5 | * Author: Matthias Riegler 6 | * 7 | * Mar 07 2014: Added Arduino and C++ Library 8 | * 9 | * September 6, 2014: Added option to switch between most popular color orders 10 | * (RGB, GRB, and BRG) -- Windell H. Oskay 11 | * 12 | * License: GNU GPL v2 (see License.txt) 13 | */ 14 | 15 | #include "WS2812.h" 16 | #include 17 | 18 | WS2812::WS2812(uint16_t num_leds) { 19 | count_led = num_leds; 20 | 21 | pixels = (uint8_t*)malloc(count_led*3); 22 | #ifdef RGB_ORDER_ON_RUNTIME 23 | offsetGreen = 0; 24 | offsetRed = 1; 25 | offsetBlue = 2; 26 | #endif 27 | } 28 | 29 | cRGB WS2812::get_crgb_at(uint16_t index) { 30 | 31 | cRGB px_value; 32 | 33 | if(index < count_led) { 34 | 35 | uint16_t tmp; 36 | tmp = index * 3; 37 | 38 | px_value.r = pixels[OFFSET_R(tmp)]; 39 | px_value.g = pixels[OFFSET_G(tmp)]; 40 | px_value.b = pixels[OFFSET_B(tmp)]; 41 | } 42 | 43 | return px_value; 44 | } 45 | 46 | uint8_t WS2812::set_crgb_at(uint16_t index, cRGB px_value) { 47 | 48 | if(index < count_led) { 49 | 50 | uint16_t tmp; 51 | tmp = index * 3; 52 | 53 | pixels[OFFSET_R(tmp)] = px_value.r; 54 | pixels[OFFSET_G(tmp)] = px_value.g; 55 | pixels[OFFSET_B(tmp)] = px_value.b; 56 | return 0; 57 | } 58 | return 1; 59 | } 60 | 61 | uint8_t WS2812::set_subpixel_at(uint16_t index, uint8_t offset, uint8_t px_value) { 62 | if (index < count_led) { 63 | uint16_t tmp; 64 | tmp = index * 3; 65 | 66 | pixels[tmp + offset] = px_value; 67 | return 0; 68 | } 69 | return 1; 70 | } 71 | 72 | void WS2812::sync() { 73 | *ws2812_port_reg |= pinMask; // Enable DDR 74 | ws2812_sendarray_mask(pixels,3*count_led,pinMask,(uint8_t*) ws2812_port,(uint8_t*) ws2812_port_reg ); 75 | } 76 | 77 | #ifdef RGB_ORDER_ON_RUNTIME 78 | void WS2812::setColorOrderGRB() { // Default color order 79 | offsetGreen = 0; 80 | offsetRed = 1; 81 | offsetBlue = 2; 82 | } 83 | 84 | void WS2812::setColorOrderRGB() { 85 | offsetRed = 0; 86 | offsetGreen = 1; 87 | offsetBlue = 2; 88 | } 89 | 90 | void WS2812::setColorOrderBRG() { 91 | offsetBlue = 0; 92 | offsetRed = 1; 93 | offsetGreen = 2; 94 | } 95 | #endif 96 | 97 | WS2812::~WS2812() { 98 | free(pixels); 99 | 100 | } 101 | 102 | #ifndef ARDUINO 103 | void WS2812::setOutput(const volatile uint8_t* port, volatile uint8_t* reg, uint8_t pin) { 104 | pinMask = (1< 24 | #include 25 | #ifndef F_CPU 26 | #define F_CPU 16000000UL 27 | #endif 28 | #include 29 | #include 30 | 31 | #ifdef ARDUINO 32 | #if (ARDUINO >= 100) 33 | #include 34 | #else 35 | #include 36 | #include 37 | #endif 38 | #endif 39 | 40 | //Easier to change cRGB into any other rgb struct 41 | #include "cRGB.h" 42 | 43 | // If you want to use the setColorOrder functions, enable this line 44 | #define RGB_ORDER_ON_RUNTIME 45 | 46 | #ifdef RGB_ORDER_ON_RUNTIME 47 | #define OFFSET_R(r) r+offsetRed 48 | #define OFFSET_G(g) g+offsetGreen 49 | #define OFFSET_B(b) b+offsetBlue 50 | #else 51 | // CHANGE YOUR STATIC RGB ORDER HERE 52 | #define OFFSET_R(r) r+1 53 | #define OFFSET_G(g) g 54 | #define OFFSET_B(b) b+2 55 | #endif 56 | 57 | class WS2812 { 58 | public: 59 | WS2812(uint16_t num_led); 60 | ~WS2812(); 61 | 62 | #ifndef ARDUINO 63 | void setOutput(const volatile uint8_t* port, volatile uint8_t* reg, uint8_t pin); 64 | #else 65 | void setOutput(uint8_t pin); 66 | #endif 67 | 68 | cRGB get_crgb_at(uint16_t index); 69 | uint8_t set_crgb_at(uint16_t index, cRGB px_value); 70 | uint8_t set_subpixel_at(uint16_t index, uint8_t offset, uint8_t px_value); 71 | 72 | void sync(); 73 | 74 | #ifdef RGB_ORDER_ON_RUNTIME 75 | void setColorOrderRGB(); 76 | void setColorOrderGRB(); 77 | void setColorOrderBRG(); 78 | #endif 79 | 80 | private: 81 | uint16_t count_led; 82 | uint8_t *pixels; 83 | 84 | #ifdef RGB_ORDER_ON_RUNTIME 85 | uint8_t offsetRed; 86 | uint8_t offsetGreen; 87 | uint8_t offsetBlue; 88 | #endif 89 | 90 | void ws2812_sendarray_mask(uint8_t *array,uint16_t length, uint8_t pinmask,uint8_t *port, uint8_t *portreg); 91 | 92 | const volatile uint8_t *ws2812_port; 93 | volatile uint8_t *ws2812_port_reg; 94 | uint8_t pinMask; 95 | }; 96 | 97 | 98 | 99 | #endif /* WS2812_H_ */ 100 | -------------------------------------------------------------------------------- /light_WS2812/cRGB.h: -------------------------------------------------------------------------------- 1 | #ifndef CRGB_H 2 | #define CRGB_H 3 | 4 | /* 5 | Control a RGB led with Hue, Saturation and Brightness (HSB / HSV ) 6 | 7 | Hue is change by an analog input. 8 | Brightness is changed by a fading function. 9 | Saturation stays constant at 255 10 | 11 | getRGB() function based on 12 | dim_curve idea by Jims 13 | 14 | created 05-01-2010 by kasperkamperman.com 15 | */ 16 | 17 | /* 18 | dim_curve 'lookup table' to compensate for the nonlinearity of human vision. 19 | Used in the getRGB function on saturation and brightness to make 'dimming' look more natural. 20 | Exponential function used to create values below : 21 | x from 0 - 255 : y = round(pow( 2.0, x+64/40.0) - 1) 22 | */ 23 | 24 | // uncomment this line if you use HSV is many projects 25 | // #define USE_HSV 26 | 27 | #ifdef USE_HSV 28 | const byte dim_curve[] = { 29 | 0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 30 | 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 31 | 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 32 | 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 33 | 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 34 | 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 35 | 15, 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 36 | 20, 20, 21, 21, 22, 22, 22, 23, 23, 24, 24, 25, 25, 25, 26, 26, 37 | 27, 27, 28, 28, 29, 29, 30, 30, 31, 32, 32, 33, 33, 34, 35, 35, 38 | 36, 36, 37, 38, 38, 39, 40, 40, 41, 42, 43, 43, 44, 45, 46, 47, 39 | 48, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 40 | 63, 64, 65, 66, 68, 69, 70, 71, 73, 74, 75, 76, 78, 79, 81, 82, 41 | 83, 85, 86, 88, 90, 91, 93, 94, 96, 98, 99, 101, 103, 105, 107, 109, 42 | 110, 112, 114, 116, 118, 121, 123, 125, 127, 129, 132, 134, 136, 139, 141, 144, 43 | 146, 149, 151, 154, 157, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, 190, 44 | 193, 196, 200, 203, 207, 211, 214, 218, 222, 226, 230, 234, 238, 242, 248, 255, 45 | }; 46 | #endif 47 | 48 | struct cRGB { 49 | uint8_t g; 50 | uint8_t r; 51 | uint8_t b; 52 | 53 | #ifdef USE_HSV 54 | void SetHSV(int hue, byte sat, byte val) { 55 | /* convert hue, saturation and brightness ( HSB/HSV ) to RGB 56 | The dim_curve is used only on brightness/value and on saturation (inverted). 57 | This looks the most natural. 58 | */ 59 | 60 | val = dim_curve[val]; 61 | sat = 255 - dim_curve[255 - sat]; 62 | 63 | int base; 64 | 65 | if (sat == 0) { // Acromatic color (gray). Hue doesn't mind. 66 | r = val; 67 | g = val; 68 | b = val; 69 | } 70 | else { 71 | base = ((255 - sat) * val) >> 8; 72 | 73 | switch (hue / 60) { 74 | case 0: 75 | r = val; 76 | g = (((val - base)*hue) / 60) + base; 77 | b = base; 78 | break; 79 | 80 | case 1: 81 | r = (((val - base)*(60 - (hue % 60))) / 60) + base; 82 | g = val; 83 | b = base; 84 | break; 85 | 86 | case 2: 87 | r = base; 88 | g = val; 89 | b = (((val - base)*(hue % 60)) / 60) + base; 90 | break; 91 | 92 | case 3: 93 | r = base; 94 | g = (((val - base)*(60 - (hue % 60))) / 60) + base; 95 | b = val; 96 | break; 97 | 98 | case 4: 99 | r = (((val - base)*(hue % 60)) / 60) + base; 100 | g = base; 101 | b = val; 102 | break; 103 | 104 | case 5: 105 | r = val; 106 | g = base; 107 | b = (((val - base)*(60 - (hue % 60))) / 60) + base; 108 | break; 109 | } 110 | } 111 | } 112 | #endif 113 | }; 114 | 115 | #endif -------------------------------------------------------------------------------- /light_WS2812/examples/Blinky/Blinky.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * light_ws2812 example 3 | * 4 | * Created: 07.03.2014 12:49:30 5 | * Author: Matthias Riegler 6 | */ 7 | 8 | #include 9 | 10 | WS2812 LED(1); // 1 LED 11 | 12 | cRGB value; 13 | 14 | void setup() { 15 | LED.setOutput(9); // Digital Pin 9 16 | } 17 | 18 | void loop() { 19 | value.b = 255; value.g = 0; value.r = 0; // RGB Value -> Blue 20 | LED.set_crgb_at(0, value); // Set value at LED found at index 0 21 | LED.sync(); // Sends the value to the LED 22 | delay(500); // Wait 500 ms 23 | 24 | value.b = 0; value.g = 0; value.r = 255; // RGB Value -> Red 25 | LED.set_crgb_at(0, value); // Set value at LED found at index 0 26 | LED.sync(); // Sends the value to the LED 27 | delay(500); // Wait 500 ms 28 | } 29 | 30 | -------------------------------------------------------------------------------- /light_WS2812/examples/fade_rgb/fade_rgb.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * light_ws2812 example 3 | * Fade LEDs in R, G, B order; demonstrate functions for changing color order. 4 | * 5 | * Created: September 6, 2014 6 | * Author: Windell Oskay (www.evilmadscientist.com) 7 | */ 8 | 9 | #include 10 | 11 | #define outputPin 7 // Digital output pin (default: 7) 12 | #define LEDCount 9 // Number of LEDs to drive (default: 9) 13 | 14 | 15 | WS2812 LED(LEDCount); 16 | cRGB value; 17 | 18 | byte intensity; 19 | byte sign; 20 | 21 | void setup() { 22 | LED.setOutput(outputPin); // Digital Pin 7 23 | 24 | /* You may uncomment one of the following three lines to switch 25 | to a different data transmission sequence for your addressable LEDs. 26 | (These functions can be used at any point in your program as needed.) */ 27 | 28 | LED.setColorOrderRGB(); // Uncomment for RGB color order 29 | //LED.setColorOrderBRG(); // Uncomment for BRG color order 30 | //LED.setColorOrderGRB(); // Uncomment for GRB color order (Default; will be used if none other is defined.) 31 | 32 | intensity = 0; 33 | sign = 1; 34 | } 35 | 36 | void loop() { 37 | int i = 0; 38 | if (sign) { 39 | intensity++; 40 | if (intensity == 255) 41 | sign = 0; 42 | } 43 | else { 44 | intensity--; 45 | if (intensity == 0) 46 | sign = 1; 47 | } 48 | 49 | while (i < LEDCount){ 50 | if ((i % 3) == 0) { // First LED, and every third after that 51 | value.b = 0; 52 | value.g = 0; 53 | value.r = intensity; // RGB Value -> Red Only 54 | LED.set_crgb_at(i, value); // Set value at LED found at index 0 55 | } 56 | else if ((i % 3) == 1) { // Second LED, and every third after that 57 | value.b = 0; 58 | value.g = intensity; 59 | value.r = 0; // RGB Value -> Green Only 60 | LED.set_crgb_at(i, value); // Set value at LED found at index 0 61 | } 62 | else { // Third LED, and every third after that 63 | value.b = intensity; 64 | value.g = 0; 65 | value.r = 0; // RGB Value -> Blue Only 66 | LED.set_crgb_at(i, value); // Set value at LED found at index 0 67 | } 68 | i++; 69 | } 70 | 71 | LED.sync(); // Sends the data to the LEDs 72 | delay(10); // Wait (ms) 73 | } 74 | -------------------------------------------------------------------------------- /light_WS2812/examples/rainbow/rainbow.ino: -------------------------------------------------------------------------------- 1 | // use the cRGB struct hsv method 2 | #define USE_HSV 3 | 4 | #include 5 | 6 | #define LEDCount 10 7 | #define outputPin 7 8 | 9 | WS2812 LED(LEDCount); 10 | cRGB value; 11 | 12 | int h = 0; //stores 0 to 614 13 | byte steps = 15; //number of hues we skip in a 360 range per update 14 | 15 | byte sat = 255; 16 | byte val = 127; 17 | 18 | long sleep = 100; //delays between update 19 | 20 | void setup() { 21 | LED.setOutput(outputPin); 22 | } 23 | 24 | void loop() { 25 | Cycle(); 26 | 27 | for(int i = 0; i < LEDCount; i++) 28 | { 29 | LED.set_crgb_at(i, value); 30 | } 31 | // Sends the data to the LEDs 32 | LED.sync(); 33 | 34 | delay(sleep); 35 | } 36 | 37 | void Cycle() 38 | { 39 | value.SetHSV(h, sat, val); 40 | 41 | h += steps; 42 | if(h > 360) 43 | { 44 | h %= 360; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /light_WS2812/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "LightWS2812", 3 | "version": "2.4.0", 4 | "keywords": "neopixel,ws2811,ws2812,apa102", 5 | "description": "Light weight library to control WS2811/WS2812 based LEDS and LED Strings", 6 | "include": "light_WS2812", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "frameworks": "arduino", 13 | "platforms": "atmelavr" 14 | } 15 | -------------------------------------------------------------------------------- /light_WS2812/library.properties: -------------------------------------------------------------------------------- 1 | name=LightWS2812 2 | version=1.0.0 3 | author=Tim Boescke (cpldcpu) 4 | maintainer=Watterott 5 | sentence=Library for WS2811/WS2812/WS2812B based LEDs 6 | paragraph=Library for WS2811/WS2812/WS2812B based LEDs 7 | category=Display 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /light_WS2812/light_ws2812.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * light weight WS2812 lib V2.1 - Arduino support 3 | * 4 | * Controls WS2811/WS2812/WS2812B RGB-LEDs 5 | * Author: Tim (cpldcpu@gmail.com) 6 | * 7 | * Jan 18th, 2014 v2.0b Initial Version 8 | * March 7th, 2014 v2.1 Added option to retarget the port register during runtime 9 | * Removes inlining to allow compiling with c++ 10 | * 11 | * License: GNU GPL v2 (see License.txt) 12 | */ 13 | 14 | #include "WS2812.h" 15 | 16 | /* 17 | This routine writes an array of bytes with RGB values to the Dataout pin 18 | using the fast 800kHz clockless WS2811/2812 protocol. 19 | */ 20 | 21 | // Timing in ns 22 | #define w_zeropulse 350 23 | #define w_onepulse 900 24 | #define w_totalperiod 1250 25 | 26 | // Fixed cycles used by the inner loop 27 | #define w_fixedlow 3 28 | #define w_fixedhigh 6 29 | #define w_fixedtotal 10 30 | 31 | // Insert NOPs to match the timing, if possible 32 | #define w_zerocycles (((F_CPU/1000)*w_zeropulse )/1000000) 33 | #define w_onecycles (((F_CPU/1000)*w_onepulse +500000)/1000000) 34 | #define w_totalcycles (((F_CPU/1000)*w_totalperiod +500000)/1000000) 35 | 36 | // w1 - nops between rising edge and falling edge - low 37 | #define w1 (w_zerocycles-w_fixedlow) 38 | // w2 nops between fe low and fe high 39 | #define w2 (w_onecycles-w_fixedhigh-w1) 40 | // w3 nops to complete loop 41 | #define w3 (w_totalcycles-w_fixedtotal-w1-w2) 42 | 43 | #if w1>0 44 | #define w1_nops w1 45 | #else 46 | #define w1_nops 0 47 | #endif 48 | 49 | // The only critical timing parameter is the minimum pulse length of the "0" 50 | // Warn or throw error if this timing can not be met with current F_CPU settings. 51 | #define w_lowtime ((w1_nops+w_fixedlow)*1000000)/(F_CPU/1000) 52 | #if w_lowtime>550 53 | #error "Light_ws2812: Sorry, the clock speed is too low. Did you set F_CPU correctly?" 54 | #elif w_lowtime>450 55 | #warning "Light_ws2812: The timing is critical and may only work on WS2812B, not on WS2812(S)." 56 | #warning "Please consider a higher clockspeed, if possible" 57 | #endif 58 | 59 | #if w2>0 60 | #define w2_nops w2 61 | #else 62 | #define w2_nops 0 63 | #endif 64 | 65 | #if w3>0 66 | #define w3_nops w3 67 | #else 68 | #define w3_nops 0 69 | #endif 70 | 71 | #define w_nop1 "nop \n\t" 72 | #define w_nop2 "rjmp .+0 \n\t" 73 | #define w_nop4 w_nop2 w_nop2 74 | #define w_nop8 w_nop4 w_nop4 75 | #define w_nop16 w_nop8 w_nop8 76 | 77 | void WS2812::ws2812_sendarray_mask(uint8_t *data,uint16_t datlen,uint8_t maskhi,uint8_t *port, uint8_t *portreg) 78 | { 79 | uint8_t curbyte,ctr,masklo; 80 | uint8_t sreg_prev; 81 | 82 | masklo = ~maskhi & *port; 83 | maskhi |= *port; 84 | sreg_prev=SREG; 85 | cli(); 86 | 87 | while (datlen--) { 88 | curbyte=*data++; 89 | 90 | asm volatile( 91 | " ldi %0,8 \n\t" 92 | "loop%=: \n\t" 93 | " st X,%3 \n\t" // '1' [02] '0' [02] - re 94 | #if (w1_nops&1) 95 | w_nop1 96 | #endif 97 | #if (w1_nops&2) 98 | w_nop2 99 | #endif 100 | #if (w1_nops&4) 101 | w_nop4 102 | #endif 103 | #if (w1_nops&8) 104 | w_nop8 105 | #endif 106 | #if (w1_nops&16) 107 | w_nop16 108 | #endif 109 | " sbrs %1,7 \n\t" // '1' [04] '0' [03] 110 | " st X,%4 \n\t" // '1' [--] '0' [05] - fe-low 111 | " lsl %1 \n\t" // '1' [05] '0' [06] 112 | #if (w2_nops&1) 113 | w_nop1 114 | #endif 115 | #if (w2_nops&2) 116 | w_nop2 117 | #endif 118 | #if (w2_nops&4) 119 | w_nop4 120 | #endif 121 | #if (w2_nops&8) 122 | w_nop8 123 | #endif 124 | #if (w2_nops&16) 125 | w_nop16 126 | #endif 127 | " brcc skipone%= \n\t" // '1' [+1] '0' [+2] - 128 | " st X,%4 \n\t" // '1' [+3] '0' [--] - fe-high 129 | "skipone%=: " // '1' [+3] '0' [+2] - 130 | 131 | #if (w3_nops&1) 132 | w_nop1 133 | #endif 134 | #if (w3_nops&2) 135 | w_nop2 136 | #endif 137 | #if (w3_nops&4) 138 | w_nop4 139 | #endif 140 | #if (w3_nops&8) 141 | w_nop8 142 | #endif 143 | #if (w3_nops&16) 144 | w_nop16 145 | #endif 146 | 147 | " dec %0 \n\t" // '1' [+4] '0' [+3] 148 | " brne loop%=\n\t" // '1' [+5] '0' [+4] 149 | : "=&d" (ctr) 150 | // : "r" (curbyte), "I" (_SFR_IO_ADDR(ws2812_PORTREG)), "r" (maskhi), "r" (masklo) 151 | : "r" (curbyte), "x" (port), "r" (maskhi), "r" (masklo) 152 | ); 153 | } 154 | 155 | SREG=sreg_prev; 156 | } 157 | -------------------------------------------------------------------------------- /light_WS2812/readme.txt: -------------------------------------------------------------------------------- 1 | https://github.com/cpldcpu/light_ws2812 2 | 3 | 4 | This is a small Ansi-C library to control WS2811/WS2812 based RGB Leds and strings. 5 | Only the 800kHz high-speed mode is supported. 6 | This library uses a bit-banging approach with cycle optimized assembler innerloops. 7 | 8 | Please find updates on https://github.com/cpldcpu/light_ws2812 9 | -------------------------------------------------------------------------------- /mSD_Shield/README.md: -------------------------------------------------------------------------------- 1 | # mSD-Shield 2 | 3 | ## Schematics 4 | The schematics can be found [here](https://github.com/watterott/mSD-Shield#msd-shield). 5 | 6 | ## Examples 7 | Examples can be found in the Arduino IDE under ```File -> Examples -> mSD_Shield``` and ```File -> Examples -> SD```. 8 | 9 | ## mSD-Shield + Ethernet-Shield 10 | If using the Ethernet-Shield together with the mSD-Shield, this must be initialized before using the SD-Card. Because otherwise the W5100 Ethernet controller blocks the SPI interface. 11 | 12 | ## mSD-Shield v2 13 | The mSD-Shield v2 uses the ICSP connector for the SPI signals and so all Arduino boards can be used. 14 | 15 | ## mSD-Shield v1 (not mSD-Shield Mega-Edition) 16 | For Hardware-SPI support on Mega boards connect the mSD-Shield v1 as follows. 17 | No Software changes are required. 18 | 19 | Mega mSD-Shield v1 20 | SCK 52 -> 13 21 | MOSI 51 -> 11 22 | MISO 50 -> 12 23 | 24 | For using the RTC on Mega boards the I2C pins have to be changed. 25 | 26 | Mega mSD-Shield v1 27 | SDA 20 -> A4 28 | SCL 21 -> A5 29 | -------------------------------------------------------------------------------- /mSD_Shield/examples/BMPDemo/BMPDemo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | BMP-File Demonstration 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | //Declare only one display ! 18 | // MI0283QT2 lcd; //MI0283QT2 Adapter v1 19 | // MI0283QT9 lcd; //MI0283QT9 Adapter v1 20 | // DisplaySPI lcd; //SPI (GLCD-Shield or MI0283QT Adapter v2) 21 | DisplayI2C lcd; //I2C (GLCD-Shield or MI0283QT Adapter v2) 22 | 23 | 24 | uint8_t OpenBMPFile(char *file, int16_t x, int16_t y) 25 | { 26 | File myFile; 27 | uint8_t buf[40]; //read buf (min. size = sizeof(BMP_DIPHeader)) 28 | BMP_Header *bmp_hd; 29 | BMP_DIPHeader *bmp_dip; 30 | int16_t width, height, w, h; 31 | uint8_t pad, result=0; 32 | 33 | //open file 34 | myFile = SD.open(file); 35 | if(myFile) 36 | { 37 | result = 1; 38 | //BMP Header 39 | myFile.read(&buf, sizeof(BMP_Header)); 40 | bmp_hd = (BMP_Header*)&buf[0]; 41 | if((bmp_hd->magic[0] == 'B') && (bmp_hd->magic[1] == 'M') && (bmp_hd->offset == 54)) 42 | { 43 | result = 2; 44 | //BMP DIP-Header 45 | myFile.read(&buf, sizeof(BMP_DIPHeader)); 46 | bmp_dip = (BMP_DIPHeader*)&buf[0]; 47 | if((bmp_dip->size == sizeof(BMP_DIPHeader)) && (bmp_dip->bitspp == 24) && (bmp_dip->compress == 0)) 48 | { 49 | result = 3; 50 | //BMP Data (1. pixel = bottom left) 51 | width = bmp_dip->width; 52 | height = bmp_dip->height; 53 | pad = width % 4; //padding (line is multiply of 4) 54 | if((x+width) <= lcd.getWidth() && (y+height) <= lcd.getHeight()) 55 | { 56 | result = 4; 57 | lcd.setArea(x, y, x+width-1, y+height-1); 58 | for(h=(y+height-1); h >= y; h--) //for every line 59 | { 60 | for(w=x; w < (x+width); w++) //for every pixel in line 61 | { 62 | myFile.read(&buf, 3); 63 | lcd.drawPixel(w, h, RGB(buf[2],buf[1],buf[0])); 64 | } 65 | if(pad) 66 | { 67 | myFile.read(&buf, pad); 68 | } 69 | } 70 | } 71 | else 72 | { 73 | lcd.drawText(x, y, "Pic out of screen!", RGB(0,0,0), RGB(255,255,255), 1); 74 | } 75 | } 76 | } 77 | 78 | myFile.close(); 79 | } 80 | 81 | return result; 82 | } 83 | 84 | 85 | void setup() 86 | { 87 | int x, i; 88 | 89 | //init Display 90 | lcd.begin(); 91 | //lcd.begin(SPI_CLOCK_DIV4, 8); //SPI Displays: spi-clk=Fcpu/4, rst-pin=8 92 | //lcd.begin(0x20, 8); //I2C Displays: addr=0x20, rst-pin=8 93 | lcd.fillScreen(RGB(255,255,255)); 94 | 95 | //init SD-Card 96 | x = lcd.drawText(5, 5, "Init SD-Card...", RGB(0,0,0), RGB(255,255,255), 1); 97 | if(!SD.begin(4)) //cs-pin=4 98 | { 99 | lcd.drawText(x, 5, "failed", RGB(0,0,0), RGB(255,255,255), 1); 100 | while(1); 101 | } 102 | 103 | //open windows bmp file (24bit RGB) 104 | x = lcd.drawText(5, 5, "Open File...", RGB(0,0,0), RGB(255,255,255), 1); 105 | i = OpenBMPFile("image.bmp", 20, 20); 106 | lcd.drawInteger(x, 5, i, 10, RGB(0,0,0), RGB(255,255,255), 1); 107 | } 108 | 109 | 110 | void loop() 111 | { 112 | //do nothing 113 | } 114 | -------------------------------------------------------------------------------- /mSD_Shield/examples/BMPDemo/image.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/watterott/Arduino-Libs/6b7f82fd2620666845ec45455dc31628165be7d2/mSD_Shield/examples/BMPDemo/image.bmp -------------------------------------------------------------------------------- /mSD_Shield/examples/DataLogger/DataLogger.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Data Logger Example 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | DS1307 rtc; 12 | 13 | 14 | void setup() 15 | { 16 | int x; 17 | 18 | //init Serial port 19 | Serial.begin(9600); 20 | while(!Serial); //wait for serial port to connect - needed for Leonardo only 21 | 22 | //init RTC 23 | Serial.print("Init RTC..."); 24 | //only set the date+time one time 25 | // rtc.set(0, 0, 8, 24, 12, 2014); //08:00:00 24.12.2014 //sec, min, hour, day, month, year 26 | rtc.start(); 27 | Serial.println("ok"); 28 | 29 | //init SD-Card 30 | Serial.print("Init SD-Card..."); 31 | if(!SD.begin(4)) //cs-pin=4 32 | { 33 | Serial.println("failed"); 34 | while(1); 35 | } 36 | else 37 | { 38 | Serial.println("ok"); 39 | } 40 | 41 | Serial.println("Start logging..."); 42 | } 43 | 44 | 45 | void loop() 46 | { 47 | String dataString = ""; //string for logging data 48 | int sec, min, hour, day, month, year; 49 | 50 | //get time from RTC 51 | rtc.get(&sec, &min, &hour, &day, &month, &year); 52 | dataString += String(hour); 53 | dataString += ":"; 54 | dataString += String(min); 55 | dataString += ":"; 56 | dataString += String(sec); 57 | dataString += ";"; 58 | dataString += String(year); 59 | dataString += "-"; 60 | dataString += String(month); 61 | dataString += "-"; 62 | dataString += String(day); 63 | dataString += ";"; 64 | 65 | //read analog input 0,1,2 66 | for(int analogPin=0; analogPin < 3; analogPin++) 67 | { 68 | int sensor = analogRead(analogPin); 69 | dataString += String(sensor); 70 | if(analogPin < 2) 71 | { 72 | dataString += ","; 73 | } 74 | } 75 | 76 | //print data to the serial port 77 | Serial.println(dataString); 78 | 79 | //open data file from SD card 80 | File dataFile = SD.open("datalog.txt", FILE_WRITE); 81 | if(dataFile) //file opened successfully 82 | { 83 | dataFile.println(dataString); 84 | dataFile.close(); 85 | } 86 | else 87 | { 88 | Serial.println("Error opening datalog.txt"); 89 | } 90 | 91 | //wait 1 second 92 | delay(1000); 93 | } 94 | -------------------------------------------------------------------------------- /mSD_Shield/examples/RTC/RTC.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RTC (Real-Time-Clock) Example 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | //Declare only one display ! 17 | // MI0283QT2 lcd; //MI0283QT2 Adapter v1 18 | // MI0283QT9 lcd; //MI0283QT9 Adapter v1 19 | // DisplaySPI lcd; //SPI (GLCD-Shield or MI0283QT Adapter v2) 20 | DisplayI2C lcd; //I2C (GLCD-Shield or MI0283QT Adapter v2) 21 | 22 | DS1307 rtc; 23 | 24 | 25 | void setup() 26 | { 27 | //init Serial port 28 | Serial.begin(9600); 29 | while(!Serial); //wait for serial port to connect - needed for Leonardo only 30 | 31 | //init Display 32 | Serial.println("Init Display..."); 33 | lcd.begin(); 34 | //lcd.begin(SPI_CLOCK_DIV4, 8); //SPI Displays: spi-clk=Fcpu/4, rst-pin=8 35 | //lcd.begin(0x20, 8); //I2C Displays: addr=0x20, rst-pin=8 36 | lcd.fillScreen(RGB(255,255,255)); 37 | 38 | //init RTC 39 | Serial.println("Init RTC..."); 40 | //only set the date+time one time 41 | // rtc.set(0, 0, 8, 24, 12, 2014); //08:00:00 24.12.2014 //sec, min, hour, day, month, year 42 | rtc.start(); 43 | } 44 | 45 | 46 | void loop() 47 | { 48 | uint8_t sec, min, hour, day, month; 49 | uint16_t year; 50 | char buf[16]; 51 | 52 | //get time from RTC 53 | rtc.get(&sec, &min, &hour, &day, &month, &year); 54 | 55 | //serial output 56 | Serial.print("\nTime: "); 57 | Serial.print(hour, DEC); 58 | Serial.print(":"); 59 | Serial.print(min, DEC); 60 | Serial.print(":"); 61 | Serial.print(sec, DEC); 62 | 63 | Serial.print("\nDate: "); 64 | Serial.print(day, DEC); 65 | Serial.print("."); 66 | Serial.print(month, DEC); 67 | Serial.print("."); 68 | Serial.print(year, DEC); 69 | 70 | //display output 71 | sprintf(buf, "%02i : %02i : %02i", hour, min, sec); 72 | lcd.drawText(10, 5, buf, RGB(0,0,0), RGB(255,255,255), 1); 73 | 74 | sprintf(buf, "%02i . %02i . %04i", day, month, year); 75 | lcd.drawText(10, 20, buf, RGB(0,0,0), RGB(255,255,255), 1); 76 | 77 | //wait a second 78 | delay(1000); 79 | } 80 | -------------------------------------------------------------------------------- /mSD_Shield/examples/ReadWrite/ReadWrite.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Read/Write File Example 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | //Declare only one display ! 17 | // MI0283QT2 lcd; //MI0283QT2 Adapter v1 18 | // MI0283QT9 lcd; //MI0283QT9 Adapter v1 19 | // DisplaySPI lcd; //SPI (GLCD-Shield or MI0283QT Adapter v2) 20 | DisplayI2C lcd; //I2C (GLCD-Shield or MI0283QT Adapter v2) 21 | 22 | File myFile; 23 | 24 | 25 | void setup() 26 | { 27 | int x; 28 | 29 | //init Serial port 30 | Serial.begin(9600); 31 | while(!Serial); //wait for serial port to connect - needed for Leonardo only 32 | 33 | //init LCD 34 | Serial.println("Init Display..."); 35 | lcd.begin(); 36 | //lcd.begin(SPI_CLOCK_DIV4, 8); //SPI Displays: spi-clk=Fcpu/4, rst-pin=8 37 | //lcd.begin(0x20, 8); //I2C Displays: addr=0x20, rst-pin=8 38 | lcd.fillScreen(RGB(255,255,255)); 39 | 40 | //init SD-Card 41 | Serial.println("Init SD-Card..."); 42 | x = lcd.drawText(5, 5, "Init SD-Card...", RGB(0,0,0), RGB(255,255,255), 1); 43 | if(!SD.begin(4)) //cs-pin=4 44 | { 45 | Serial.println("failed"); 46 | lcd.drawText(x, 5, "failed", RGB(0,0,0), RGB(255,255,255), 1); 47 | while(1); 48 | } 49 | 50 | //open file for writing 51 | Serial.println("Open File..."); 52 | x = lcd.drawText(5, 5, "Open File...", RGB(0,0,0), RGB(255,255,255), 1); 53 | myFile = SD.open("test.txt", FILE_WRITE); 54 | if(myFile) 55 | { 56 | Serial.println("Writing..."); 57 | lcd.drawText(5, 5, "Writing...", RGB(0,0,0), RGB(255,255,255), 1); 58 | myFile.println("This is a Test: ABC 123"); 59 | myFile.close(); 60 | } 61 | else 62 | { 63 | Serial.println("error"); 64 | lcd.drawText(x, 5, "error", RGB(0,0,0), RGB(255,255,255), 1); 65 | } 66 | 67 | //open file for reading 68 | Serial.println("Open File..."); 69 | x = lcd.drawText(5, 5, "Open File...", RGB(0,0,0), RGB(255,255,255), 1); 70 | myFile = SD.open("test.txt"); 71 | if(myFile) 72 | { 73 | Serial.println("Reading..."); 74 | lcd.drawText(x, 5, "Reading...", RGB(0,0,0), RGB(255,255,255), 1); 75 | lcd.setCursor(0, 20); 76 | while(myFile.available()) 77 | { 78 | uint8_t c; 79 | c = myFile.read(); 80 | Serial.write(c); 81 | lcd.print((char)c); 82 | } 83 | myFile.close(); 84 | } 85 | else 86 | { 87 | Serial.println("error"); 88 | lcd.drawText(x, 5, "error", RGB(0,0,0), RGB(255,255,255), 1); 89 | } 90 | } 91 | 92 | 93 | void loop() 94 | { 95 | //do nothing 96 | } 97 | -------------------------------------------------------------------------------- /mSD_Shield/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mSD_Shield", 3 | "version": "1.0.0", 4 | "keywords": "microsd, rtc, display, logging", 5 | "description": "mSD-Shield (Display, microSD, RTC)", 6 | "include": "mSD_Shield", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/watterott/Arduino-Libs.git" 11 | }, 12 | "frameworks": "arduino", 13 | "platforms": "atmelavr" 14 | } 15 | -------------------------------------------------------------------------------- /mSD_Shield/library.properties: -------------------------------------------------------------------------------- 1 | name=mSD_Shield 2 | version=1.0.0 3 | author=Watterott 4 | maintainer=Watterott 5 | sentence=mSD-Shield (Display, microSD, RTC) 6 | paragraph=mSD-Shield (Display, microSD, RTC) 7 | category=Communication 8 | url=https://github.com/watterott/Arduino-Libs 9 | architectures=* 10 | -------------------------------------------------------------------------------- /mSD_Shield/mSD_Shield.h: -------------------------------------------------------------------------------- 1 | //empty file, workaround for libraries containing only examples 2 | --------------------------------------------------------------------------------