├── Grove - ADC ├── main.o ├── ADC121.o ├── ADC121_DEMO ├── Makefile ├── main.cpp ├── ADC121.h └── ADC121.cpp ├── Grove - Barometer_Sensor ├── Demo ├── main.o ├── Barometer.o ├── Makefile ├── main.cpp ├── Barometer.h └── Barometer.cpp ├── Grove - Digital_Light_Sensor ├── DLS ├── main.o ├── Digital_Light_TSL2561.o ├── Makefile ├── main.cpp ├── Digital_Light_TSL2561.h └── Digital_Light_TSL2561.cpp ├── Grove - OLED Display 128x64 ├── OLED ├── main.o ├── SeeedOLED.o ├── README.md ├── Makefile ├── main.cpp ├── font_16x24.h ├── font_8x8.h ├── SeeedOLED.h └── SeeedOLED.cpp ├── Grove - Temperature and Humidity Sensor Pro ├── dht22.o ├── locking.o ├── Seeed_DHT22 ├── Makefile ├── locking.h ├── locking.c ├── config.h └── dht22.c ├── .gitattributes ├── .github └── workflows │ └── sync_issues.yml ├── License.txt ├── Grove - Relay └── relay.py ├── README.md ├── Grove - PIR Motion Sensor └── PIR_sensor.py ├── .gitignore └── Grove - Ultrasonic Ranger └── ultrasonic.py /Grove - ADC/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Grove-RaspberryPi/HEAD/Grove - ADC/main.o -------------------------------------------------------------------------------- /Grove - ADC/ADC121.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Grove-RaspberryPi/HEAD/Grove - ADC/ADC121.o -------------------------------------------------------------------------------- /Grove - ADC/ADC121_DEMO: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Grove-RaspberryPi/HEAD/Grove - ADC/ADC121_DEMO -------------------------------------------------------------------------------- /Grove - Barometer_Sensor/Demo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Grove-RaspberryPi/HEAD/Grove - Barometer_Sensor/Demo -------------------------------------------------------------------------------- /Grove - Barometer_Sensor/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Grove-RaspberryPi/HEAD/Grove - Barometer_Sensor/main.o -------------------------------------------------------------------------------- /Grove - Digital_Light_Sensor/DLS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Grove-RaspberryPi/HEAD/Grove - Digital_Light_Sensor/DLS -------------------------------------------------------------------------------- /Grove - OLED Display 128x64/OLED: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Grove-RaspberryPi/HEAD/Grove - OLED Display 128x64/OLED -------------------------------------------------------------------------------- /Grove - Barometer_Sensor/Barometer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Grove-RaspberryPi/HEAD/Grove - Barometer_Sensor/Barometer.o -------------------------------------------------------------------------------- /Grove - Digital_Light_Sensor/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Grove-RaspberryPi/HEAD/Grove - Digital_Light_Sensor/main.o -------------------------------------------------------------------------------- /Grove - OLED Display 128x64/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Grove-RaspberryPi/HEAD/Grove - OLED Display 128x64/main.o -------------------------------------------------------------------------------- /Grove - OLED Display 128x64/SeeedOLED.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Grove-RaspberryPi/HEAD/Grove - OLED Display 128x64/SeeedOLED.o -------------------------------------------------------------------------------- /Grove - Temperature and Humidity Sensor Pro/dht22.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Grove-RaspberryPi/HEAD/Grove - Temperature and Humidity Sensor Pro/dht22.o -------------------------------------------------------------------------------- /Grove - Digital_Light_Sensor/Digital_Light_TSL2561.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Grove-RaspberryPi/HEAD/Grove - Digital_Light_Sensor/Digital_Light_TSL2561.o -------------------------------------------------------------------------------- /Grove - Temperature and Humidity Sensor Pro/locking.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Grove-RaspberryPi/HEAD/Grove - Temperature and Humidity Sensor Pro/locking.o -------------------------------------------------------------------------------- /Grove - Temperature and Humidity Sensor Pro/Seeed_DHT22: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/Grove-RaspberryPi/HEAD/Grove - Temperature and Humidity Sensor Pro/Seeed_DHT22 -------------------------------------------------------------------------------- /Grove - ADC/Makefile: -------------------------------------------------------------------------------- 1 | CC = g++ 2 | CFLAGS = -Wall -O2 -I/usr/local/include -I. 3 | DEPS = 4 | OBJ = main.o ADC121.o 5 | 6 | %.o: %.c $(DEPS) 7 | $(CC) -c -o $@ $< $(CFLAGS) 8 | 9 | ADC121_DEMO: $(OBJ) 10 | $(CC) -o $@ $^ $(CFLAGS) 11 | 12 | clean: 13 | rm ./*.o 14 | rm ADC121_DEMO 15 | -------------------------------------------------------------------------------- /Grove - OLED Display 128x64/README.md: -------------------------------------------------------------------------------- 1 | Use a 128x64 OLED Display (based on SSD1308 Driver) with your Raspberry Pi 2 | 3 | Based on Wim Huiskamps mbed library: http://mbed.org/users/wim/code/SSD1308_128x64_I2C/ 4 | 5 | CAUTION! 6 | Dont connect this Display to a 3.3V or 5V pin on your RPi. 7 | Use a 3.3V VReg connected to 5V! 8 | -------------------------------------------------------------------------------- /Grove - OLED Display 128x64/Makefile: -------------------------------------------------------------------------------- 1 | CC = g++ 2 | CFLAGS = -Wall -fstack-protector -D_FORTIFY_SOURCE=2 -O2 -I/usr/local/include -I. 3 | DEPS = 4 | OBJ = main.o SeeedOLED.o 5 | 6 | %.o: %.c $(DEPS) 7 | $(CC) -c -o $@ $< $(CFLAGS) 8 | 9 | OLED: $(OBJ) 10 | $(CC) -o $@ $^ $(CFLAGS) 11 | 12 | clean: 13 | rm ./*.o 14 | rm OLED 15 | -------------------------------------------------------------------------------- /Grove - Digital_Light_Sensor/Makefile: -------------------------------------------------------------------------------- 1 | CC = g++ 2 | CFLAGS = -Wall -fstack-protector -D_FORTIFY_SOURCE=2 -O2 -I/usr/local/include -I. 3 | DEPS = 4 | OBJ = main.o Digital_Light_TSL2561.o 5 | 6 | %.o: %.c $(DEPS) 7 | $(CC) -c -o $@ $< $(CFLAGS) 8 | 9 | DLS: $(OBJ) 10 | $(CC) -o $@ $^ $(CFLAGS) 11 | 12 | clean: 13 | rm ./*.o 14 | rm DLS 15 | -------------------------------------------------------------------------------- /Grove - Barometer_Sensor/Makefile: -------------------------------------------------------------------------------- 1 | CC = g++ 2 | CFLAGS = -Wall -fstack-protector -D_FORTIFY_SOURCE=2 -O2 -I/usr/local/include -I. 3 | DEPS = 4 | OBJ = main.o Barometer.o 5 | 6 | %.o: %.c $(DEPS) 7 | $(CC) -c -o $@ $< $(CFLAGS) 8 | 9 | barometerDemo: $(OBJ) 10 | $(CC) -o $@ $^ $(CFLAGS) 11 | 12 | clean: 13 | rm ./*.o 14 | rm barometerDemo 15 | -------------------------------------------------------------------------------- /Grove - Temperature and Humidity Sensor Pro/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | CFLAGS = -std=c99 -Wall -fstack-protector -D_FORTIFY_SOURCE=2 -O2 -I/usr/local/include -I. -lwiringPi 3 | DEPS = 4 | OBJ = dht22.o locking.o 5 | 6 | %.o: %.c $(DEPS) 7 | $(CC) -c -o $@ $< $(CFLAGS) 8 | 9 | Seeed_DHT22: $(OBJ) 10 | gcc -o $@ $^ $(CFLAGS) 11 | 12 | clean: 13 | rm ./*.o 14 | rm Seeed_DHT22 15 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.github/workflows/sync_issues.yml: -------------------------------------------------------------------------------- 1 | name: Automate Issue Management 2 | 3 | on: 4 | issues: 5 | types: 6 | - opened 7 | - edited 8 | - assigned 9 | - unassigned 10 | - labeled 11 | - unlabeled 12 | - reopened 13 | 14 | jobs: 15 | add_issue_to_project: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Add issue to GitHub Project 19 | uses: actions/add-to-project@v1.0.2 20 | with: 21 | project-url: https://github.com/orgs/Seeed-Studio/projects/17 22 | github-token: ${{ secrets.ISSUE_ASSEMBLE }} 23 | labeled: bug 24 | label-operator: NOT -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Seeed Technology Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /Grove - Temperature and Humidity Sensor Pro/locking.h: -------------------------------------------------------------------------------- 1 | /* 2 | * locking.h 3 | * Prevents rapid use of application by implementing a file lock 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : technion@lolware.net 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | #define LOCKFILE "/var/run/dht.lock" 33 | 34 | int open_lockfile(const char *filename); 35 | void close_lockfile(int fd); 36 | 37 | -------------------------------------------------------------------------------- /Grove - Relay/relay.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | """ 3 | * relay.py 4 | * A library for relay at RP 5 | * 6 | * Copyright (c) 2012 seeed technology inc. 7 | * Website : www.seeed.cc 8 | * Author : seeed fellow 9 | * Create Time: 10 | * Change Log : 11 | * 12 | * The MIT License (MIT) 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | """ 32 | import time 33 | import RPi.GPIO as GPIO 34 | 35 | GPIO_RELAY = 11 36 | 37 | def relay(): 38 | #GPIO.cleanup() 39 | GPIO.setup(GPIO_RELAY, GPIO.OUT) 40 | while True: 41 | GPIO.output(GPIO_RELAY, GPIO.HIGH) 42 | #time.sleep(1) 43 | time.sleep(0.5) 44 | GPIO.output(GPIO_RELAY, GPIO.LOW) 45 | time.sleep(0.5) 46 | 47 | if __name__ == '__main__': 48 | 49 | 50 | # rpi board gpio or bcm gpio 51 | GPIO.setmode(GPIO.BOARD) 52 | 53 | # loop method 54 | relay() 55 | -------------------------------------------------------------------------------- /Grove - ADC/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * main.cpp 3 | * Demo code for RP's ADC 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : seeed fellow 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include "ADC121.h" 39 | 40 | int main () { 41 | 42 | ADC121 mADC121 = ADC121(0x55); 43 | 44 | 45 | // mADC121.initADC(); 46 | 47 | 48 | int i = 0; 49 | for(i; i < 20; i++){ 50 | 51 | std::cout << "ADC Volue: " << mADC121.readADC() << std::endl; 52 | } 53 | 54 | //while(1) { 55 | //std::cout << "ADC Volue: " << mADC121.readADC() << std::endl; 56 | //} 57 | 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Grove-RaspberryPi 2 | ----------------- 3 | 4 | SeeedStudio Grove Library for Raspberry Pi 5 | 6 | 7 | All librarys is test the Seeed Studio Grove series in Raspberry Pi. 8 | 9 | 10 | You can find all Grove series module [here][1] 11 | 12 | 13 | ![Grove-RaspberryPi][2] 14 | 15 | 16 | ### Usage: 17 | 18 | With the C library, it had a Makefile, you just run `make` to build it. 19 | 20 | For the Python application, run it with `python ###library_name###.py`. 21 | 22 | There are an [article][3] about how to use it. 23 | 24 | ---- 25 | 26 | This software is written by [xiaobo][4] for seeed studio and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check License.txt for more information.
27 | 28 | Contributing to this software is warmly welcomed. You can do this basically by
29 | [forking](https://help.github.com/articles/fork-a-repo), committing modifications and then [pulling requests](https://help.github.com/articles/using-pull-requests) (follow the links above
30 | for operating guide). Adding change log and your contact into file header is encouraged.
31 | Thanks for your contribution. 32 | 33 | Seeed is a hardware innovation platform for makers to grow inspirations into differentiating products. By working closely with technology providers of all scale, Seeed provides accessible technologies with quality, speed and supply chain knowledge. When prototypes are ready to iterate, Seeed helps productize 1 to 1,000 pcs using in-house engineering, supply chain management and agile manufacture forces. Seeed also team up with incubators, Chinese tech ecosystem, investors and distribution channels to portal Maker startups beyond. 34 | 35 | 36 | [1]: http://www.seeedstudio.com/wiki/GROVE_System 37 | [2]: http://www.seeedstudio.com/wiki/images/9/92/QQ%E5%9B%BE%E7%89%8720140108102207.jpg 38 | [3]: http://bbs.xiaomi.cn/thread-7797152-1-1.html 39 | [4]: mailto://yexiaobo@seeedstudio.com 40 | 41 | 42 | [![Analytics](https://ga-beacon.appspot.com/UA-46589105-3/Grove-RaspberryPi)](https://github.com/igrigorik/ga-beacon) 43 | -------------------------------------------------------------------------------- /Grove - ADC/ADC121.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ADC121.h 3 | * Demo code for RP's ADC 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : seeed fellow 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | 33 | #include 34 | 35 | #ifndef __ADC121_H__ 36 | #define __ADC121_H__ 37 | 38 | #define ADDR_ADC121 0x55 39 | #define REG_ADDR_RESULT 0x00 40 | #define REG_ADDR_ALERT 0x01 41 | #define REG_ADDR_CONFIG 0x02 42 | #define REG_ADDR_LIMITL 0x03 43 | #define REG_ADDR_LIMITH 0x04 44 | #define REG_ADDR_HYST 0x05 45 | #define REG_ADDR_CONVL 0x06 46 | #define REG_ADDR_CONVH 0x07 47 | 48 | class ADC121 { 49 | 50 | public: 51 | ADC121(uint16_t address); 52 | virtual ~ADC121(); 53 | 54 | void initADC(); 55 | float readADC(); 56 | }; 57 | 58 | 59 | #endif //__ADC121_H__ 60 | -------------------------------------------------------------------------------- /Grove - Digital_Light_Sensor/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * main.cpp 3 | * A library for TSL2561 at RP 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : zhangkun 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "Digital_Light_TSL2561.h" 39 | 40 | using namespace std; 41 | 42 | int main () 43 | { 44 | uint16_t a,b,c; 45 | a = 0; 46 | b = 0; 47 | c = 1; 48 | 49 | uint16_t address = 0x29; /* i2c device address */ 50 | Digital_Light_TSL2561 light = Digital_Light_TSL2561(address); 51 | 52 | cout << "Seeed Studio Digital Light Sensor" << endl; 53 | while(1) { 54 | light.getLux(); 55 | cout << "The light value is: " << light.calculateLux(a,b,c) << endl; 56 | } 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /Grove - PIR Motion Sensor/PIR_sensor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | * PIR_sensor.py 5 | * A library for PIR sensor at RP 6 | * 7 | * Copyright (c) 2012 seeed technology inc. 8 | * Website : www.seeed.cc 9 | * Author : seeed fellow 10 | * Create Time: 11 | * Change Log : 12 | * 13 | * The MIT License (MIT) 14 | * 15 | * Permission is hereby granted, free of charge, to any person obtaining a copy 16 | * of this software and associated documentation files (the "Software"), to deal 17 | * in the Software without restriction, including without limitation the rights 18 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 19 | * copies of the Software, and to permit persons to whom the Software is 20 | * furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in 23 | * all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 31 | * THE SOFTWARE. 32 | """ 33 | 34 | import time 35 | import RPi.GPIO as GPIO 36 | 37 | GPIO_PIR = 11 38 | 39 | 40 | def detectedAndPrint(): 41 | GPIO.setup(GPIO_PIR, GPIO.IN) 42 | print "Nothing" 43 | while 1: 44 | isDetected() 45 | time.sleep(0.1) 46 | print "PIR sensor detected some stuff" 47 | 48 | 49 | def isDetected(): 50 | while GPIO.input(GPIO_PIR) == GPIO.LOW: 51 | return False 52 | 53 | while GPIO.input(GPIO_PIR) == GPIO.HIGH: 54 | return True 55 | 56 | 57 | if __name__ == '__main__': 58 | # rpi board gpio or bcm gpio 59 | GPIO.setmode(GPIO.BOARD) 60 | 61 | # loop method 62 | detectedAndPrint() 63 | -------------------------------------------------------------------------------- /Grove - Barometer_Sensor/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * main.cpp 3 | * A library for barometer at RP 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : LG 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "Barometer.h" 40 | 41 | int main(){ 42 | float temperature; 43 | float pressure; 44 | float atm; 45 | float altitude; 46 | 47 | Barometer mBarometer = Barometer(); 48 | 49 | int i = 0; 50 | 51 | for(i; i< 10 ;i++) { 52 | 53 | temperature = mBarometer.bmp085GetTemperature(mBarometer.bmp085ReadUT()); //Get the temperature, bmp085ReadUT MUST be called first 54 | pressure = mBarometer.bmp085GetPressure(mBarometer.bmp085ReadUP());//Get the temperature 55 | altitude = mBarometer.calcAltitude(pressure); //Uncompensated caculation - in Meters 56 | atm = pressure / 101325; 57 | 58 | std::cout << "Temperature: " << temperature << " deg c" << std::endl; 59 | std::cout << "Pressure: " << pressure << " Pa" << std::endl; 60 | std::cout << "Ralated Atmosphere: " << atm << std::endl; 61 | std::cout << "Altitude: " << altitude << " m" << std::endl; 62 | std::cout << std::endl; 63 | } 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /Grove - Barometer_Sensor/Barometer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Barometer.h 3 | * A library for barometer at RP 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : LG 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | 33 | #ifndef __BAROMETER_H__ 34 | #define __BAROMETER_H__ 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | const unsigned char OSS = 0; 42 | 43 | #define BMP085_ADDRESS 0x77 44 | class Barometer 45 | { 46 | public: 47 | Barometer(); 48 | virtual ~Barometer(); 49 | void init(void); 50 | long PressureCompensate; 51 | float bmp085GetTemperature(uint16_t ut); 52 | long bmp085GetPressure(unsigned long up); 53 | float calcAltitude(float pressure); 54 | uint16_t bmp085ReadUT(void); 55 | unsigned long bmp085ReadUP(void); 56 | 57 | private: 58 | int16_t ac1; 59 | int16_t ac2; 60 | int16_t ac3; 61 | uint16_t ac4; 62 | uint16_t ac5; 63 | uint16_t ac6; 64 | int16_t b1; 65 | int16_t b2; 66 | int16_t mb; 67 | int16_t mc; 68 | int16_t md; 69 | char bmp085Read(unsigned char address); 70 | int16_t bmp085ReadInt(unsigned char address); 71 | void writeRegister(int16_t deviceAddress, unsigned char address, unsigned char val); 72 | int16_t readRegister(int16_t deviceAddress, unsigned char address); 73 | }; 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /Grove - Temperature and Humidity Sensor Pro/locking.c: -------------------------------------------------------------------------------- 1 | /* 2 | * locking.c 3 | * Prevents rapid use of application by implementing a file lock 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : technion@lolware.net 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | int open_lockfile(const char *filename) 41 | { 42 | int fd; 43 | fd = open(filename, O_CREAT | O_RDONLY, 0600); 44 | 45 | if (fd < 0) 46 | { 47 | printf("Failed to access lock file: %s\nerror: %s\n", 48 | filename, strerror(errno)); 49 | exit(EXIT_FAILURE); 50 | } 51 | 52 | while(flock(fd, LOCK_EX | LOCK_NB) == -1) 53 | { 54 | if(errno == EWOULDBLOCK) 55 | { 56 | printf("Lock file is in use, exiting...\n"); 57 | /* If the lockfile is in use, we COULD sleep and try again. 58 | * However, a lockfile would more likely indicate an already runaway 59 | * process. 60 | */ 61 | exit(EXIT_FAILURE); 62 | } 63 | perror("Flock failed"); 64 | exit(EXIT_FAILURE); 65 | } 66 | return fd; 67 | } 68 | 69 | void close_lockfile(int fd) 70 | { 71 | if(flock(fd, LOCK_UN) == -1) 72 | { 73 | perror("Failed to unlock file"); 74 | exit(EXIT_FAILURE); 75 | } 76 | if(close(fd) == -1) 77 | { 78 | perror("Closing descriptor on lock file failed"); 79 | exit(EXIT_FAILURE); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | [Dd]ebug/ 46 | [Rr]elease/ 47 | *_i.c 48 | *_p.c 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.vspscc 63 | .builds 64 | *.dotCover 65 | 66 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 67 | #packages/ 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | 76 | # Visual Studio profiler 77 | *.psess 78 | *.vsp 79 | 80 | # ReSharper is a .NET coding add-in 81 | _ReSharper* 82 | 83 | # Installshield output folder 84 | [Ee]xpress 85 | 86 | # DocProject is a documentation generator add-in 87 | DocProject/buildhelp/ 88 | DocProject/Help/*.HxT 89 | DocProject/Help/*.HxC 90 | DocProject/Help/*.hhc 91 | DocProject/Help/*.hhk 92 | DocProject/Help/*.hhp 93 | DocProject/Help/Html2 94 | DocProject/Help/html 95 | 96 | # Click-Once directory 97 | publish 98 | 99 | # Others 100 | [Bb]in 101 | [Oo]bj 102 | sql 103 | TestResults 104 | *.Cache 105 | ClientBin 106 | stylecop.* 107 | ~$* 108 | *.dbmdl 109 | Generated_Code #added for RIA/Silverlight projects 110 | 111 | # Backup & report files from converting an old project file to a newer 112 | # Visual Studio version. Backup files are not needed, because we have git ;-) 113 | _UpgradeReport_Files/ 114 | Backup*/ 115 | UpgradeLog*.XML 116 | 117 | 118 | 119 | ############ 120 | ## Windows 121 | ############ 122 | 123 | # Windows image file caches 124 | Thumbs.db 125 | 126 | # Folder config file 127 | Desktop.ini 128 | 129 | 130 | ############# 131 | ## Python 132 | ############# 133 | 134 | *.py[co] 135 | 136 | # Packages 137 | *.egg 138 | *.egg-info 139 | dist 140 | build 141 | eggs 142 | parts 143 | bin 144 | var 145 | sdist 146 | develop-eggs 147 | .installed.cfg 148 | 149 | # Installer logs 150 | pip-log.txt 151 | 152 | # Unit test / coverage reports 153 | .coverage 154 | .tox 155 | 156 | #Translations 157 | *.mo 158 | 159 | #Mr Developer 160 | .mr.developer.cfg 161 | 162 | # Mac crap 163 | .DS_Store 164 | -------------------------------------------------------------------------------- /Grove - Ultrasonic Ranger/ultrasonic.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | * ultrasonic.py 4 | * A library for ultrasonic sensor at RP 5 | * 6 | * Copyright (c) 2012 seeed technology inc. 7 | * Website : www.seeed.cc 8 | * Author : seeed fellow 9 | * Create Time: 10 | * Change Log : 11 | * 12 | * The MIT License (MIT) 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | """ 32 | import RPi.GPIO as GPIO 33 | import time 34 | 35 | GPIO_SIG = 11 36 | 37 | 38 | def getAndPrint(): 39 | 40 | print "SeeedStudio Grove Ultrasonic get data and print" 41 | 42 | # test 100 times 43 | for i in range(100): 44 | measurementInCM() 45 | 46 | # Reset GPIO settings 47 | GPIO.cleanup() 48 | 49 | 50 | def measurementInCM(): 51 | 52 | # setup the GPIO_SIG as output 53 | GPIO.setup(GPIO_SIG, GPIO.OUT) 54 | 55 | GPIO.output(GPIO_SIG, GPIO.LOW) 56 | time.sleep(0.2) 57 | GPIO.output(GPIO_SIG, GPIO.HIGH) 58 | time.sleep(0.5) 59 | GPIO.output(GPIO_SIG, GPIO.LOW) 60 | start = time.time() 61 | 62 | # setup GPIO_SIG as input 63 | GPIO.setup(GPIO_SIG, GPIO.IN) 64 | 65 | # get duration from Ultrasonic SIG pin 66 | while GPIO.input(GPIO_SIG) == 0: 67 | start = time.time() 68 | 69 | while GPIO.input(GPIO_SIG) == 1: 70 | stop = time.time() 71 | 72 | measurementPulse(start, stop) 73 | 74 | 75 | def measurementPulse(start, stop): 76 | 77 | print "Ultrasonic Measurement" 78 | 79 | # Calculate pulse length 80 | elapsed = stop-start 81 | 82 | # Distance pulse travelled in that time is time 83 | # multiplied by the speed of sound (cm/s) 84 | distance = elapsed * 34300 85 | 86 | # That was the distance there and back so halve the value 87 | distance = distance / 2 88 | 89 | print "Distance : %.1f CM" % distance 90 | 91 | 92 | if __name__ == '__main__': 93 | # rpi board gpio or bcm gpio 94 | GPIO.setmode(GPIO.BOARD) 95 | 96 | # loop method 97 | getAndPrint() 98 | -------------------------------------------------------------------------------- /Grove - Temperature and Humidity Sensor Pro/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * A library for Grove - Temperature and Humidity Sensor Pro at RP 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : technion@lolware.net, yexiaobo@seeedstudio.com 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | /* Define to 1 if you have the header file. */ 33 | #define HAVE_INTTYPES_H 1 34 | 35 | /* Define to 1 if you have the `wiringPi' library (-lwiringPi). */ 36 | #define HAVE_LIBWIRINGPI 1 37 | 38 | /* Define to 1 if you have the header file. */ 39 | #define HAVE_MEMORY_H 1 40 | 41 | /* Define to 1 if you have the header file. */ 42 | #define HAVE_STDINT_H 1 43 | 44 | /* Define to 1 if you have the header file. */ 45 | #define HAVE_STDLIB_H 1 46 | 47 | /* Define to 1 if you have the header file. */ 48 | #define HAVE_STRINGS_H 1 49 | 50 | /* Define to 1 if you have the header file. */ 51 | #define HAVE_STRING_H 1 52 | 53 | /* Define to 1 if you have the header file. */ 54 | #define HAVE_SYS_STAT_H 1 55 | 56 | /* Define to 1 if you have the header file. */ 57 | #define HAVE_SYS_TYPES_H 1 58 | 59 | /* Define to 1 if you have the header file. */ 60 | #define HAVE_UNISTD_H 1 61 | 62 | /* Name of package */ 63 | #define PACKAGE "lolware_dht" 64 | 65 | /* Define to the address where bug reports for this package should be sent. */ 66 | #define PACKAGE_BUGREPORT "" 67 | 68 | /* Define to the full name of this package. */ 69 | #define PACKAGE_NAME "lolware_dht" 70 | 71 | /* Define to the full name and version of this package. */ 72 | #define PACKAGE_STRING "lolware_dht version-0.1" 73 | 74 | /* Define to the one symbol short name of this package. */ 75 | #define PACKAGE_TARNAME "lolware_dht" 76 | 77 | /* Define to the home page for this package. */ 78 | #define PACKAGE_URL "" 79 | 80 | /* Define to the version of this package. */ 81 | #define PACKAGE_VERSION "version-0.1" 82 | 83 | /* Define to 1 if you have the ANSI C header files. */ 84 | #define STDC_HEADERS 1 85 | 86 | /* Version number of package */ 87 | #define VERSION "0.0.1" 88 | -------------------------------------------------------------------------------- /Grove - ADC/ADC121.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ADC121.cpp 3 | * Demo code for RP's ADC 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : seeed fellow 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "ADC121.h" 42 | 43 | 44 | ADC121::ADC121(uint16_t address){ 45 | 46 | } 47 | 48 | ADC121::~ADC121(){ 49 | 50 | } 51 | 52 | void ADC121::initADC(){ 53 | 54 | int file; 55 | uint16_t data[1] = {0x20}; 56 | 57 | /* open the i2c dev */ 58 | if((file = open("/dev/i2c-1",O_RDWR)) < 0) { 59 | printf("Failed to open the bus."); 60 | } 61 | 62 | if(ioctl(file,I2C_SLAVE,ADDR_ADC121) < 0) { 63 | printf("Failed to acquire bus access and/or talk to slave.\n"); 64 | } 65 | 66 | write(file,data,1); 67 | close(file); 68 | } 69 | 70 | float ADC121::readADC(){ 71 | 72 | int file; 73 | uint16_t initData[2] = {REG_ADDR_CONFIG, 0x20}; 74 | //uint16_t iData[1] = {0x20}; 75 | 76 | uint16_t data[1] = {REG_ADDR_RESULT}; 77 | uint16_t buf[2] = {0,0}; 78 | //int b[1] = {0}; 79 | //printf("int b[0] = %d\n", &b[0]); 80 | //printf("init buf[0] = %d, buf[1] = %d\n", buf[0], buf[1]); 81 | 82 | /* open the i2c dev */ 83 | if((file = open("/dev/i2c-1",O_RDWR)) < 0) { 84 | printf("Failed to open the bus."); 85 | } 86 | 87 | /* control the i2c device, and get the file handle */ 88 | if(ioctl(file,I2C_SLAVE,ADDR_ADC121) < 0) { 89 | printf("Failed to acquire bus access and/or talk to slave.\n"); 90 | } 91 | 92 | write(file, initData, 2); /* init ADC */ 93 | //write(file, iData, 1); [> init ADC <] 94 | write(file, data, 1); /* writing REG_ADDR_RESULT to get data */ 95 | sleep(0.1); /* sleep unit is s */ 96 | 97 | 98 | 99 | // read from ADDR_ADC121 100 | if(read(file, buf, 2)) { 101 | 102 | //printf("b[0] = %d\n", &b[0]); 103 | //printf("buf[0] = %d, buf[1] = %d\n", buf[0], buf[1]); 104 | 105 | // get data 106 | int x0 = buf[0] & 0x0f; 107 | int x1 = buf[1]; 108 | 109 | x0 = x0 << 8; 110 | 111 | int x2 = x0+x1; 112 | //printf("x2: %d\n", x2); 113 | 114 | // calculating the data 115 | float value = x2/4096.0*3.0*2.0; 116 | close(file); 117 | return value; 118 | 119 | } else { 120 | printf("can't read anything"); 121 | close(file); 122 | 123 | return -1; 124 | } 125 | 126 | 127 | } 128 | 129 | -------------------------------------------------------------------------------- /Grove - OLED Display 128x64/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * main.cpp 3 | * A library for OLED Display 128*64 at RP 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : seeed fellow 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "SeeedOLED.h" 37 | 38 | using namespace std; 39 | 40 | SeeedOLED oled = SeeedOLED(0x3c); 41 | 42 | string GetStdoutFromCommand(string cmd) { 43 | int len; 44 | string data; 45 | FILE * stream; 46 | const int max_buffer = 256; 47 | char buffer[max_buffer]; 48 | cmd.append(" 2>&1"); 49 | 50 | stream = popen(cmd.c_str(), "r"); 51 | if (stream) { 52 | while (!feof(stream)) { 53 | if (fgets(buffer, max_buffer, stream) != NULL) { 54 | data.append(buffer); 55 | } 56 | } 57 | pclose(stream); 58 | } 59 | len = data.size() - 1; 60 | data = data.substr(0, len); 61 | return data; 62 | } 63 | 64 | int main () 65 | { 66 | while(1) { 67 | oled.writeString(0, 0, " Seeed Studio Pi "); 68 | string line2 = GetStdoutFromCommand("awk '{print $3}' /proc/version"); // kernel release 69 | oled.writeString(1, 0, (char*)line2.c_str()); 70 | 71 | string line3 = "Temp: "; 72 | line3.append(GetStdoutFromCommand("awk '{printf \"%.1f\\n\", $1 / 1000}' /sys/class/thermal/thermal_zone0/temp")); // GPU temperature 73 | line3.append("oC"); 74 | oled.writeString(2, 0, (char*)line3.c_str()); 75 | 76 | string line4 = GetStdoutFromCommand("date +\"%H:%M %Y-%m-%d\""); // time and date 77 | oled.writeString(3, 0, (char*)line4.c_str()); 78 | 79 | string line5 = "Uptime: "; 80 | line5.append(GetStdoutFromCommand("awk '{printf \"%.1f\\n\", $1 / 3600}' /proc/uptime")); // uptime 81 | line5.append("h"); 82 | oled.writeString(4, 0, (char*)line5.c_str()); 83 | 84 | string line6 = " "; 85 | line6.append(GetStdoutFromCommand("awk '{print $1\"/\"$2\"/\"$3}' /proc/loadavg")); // CPU usage 86 | oled.writeString(5, 0, (char*)line6.c_str()); 87 | 88 | string line7 = "RAM: "; 89 | line7.append(GetStdoutFromCommand("sed -n '1p' /proc/meminfo | awk '{printf \"%.0f\\n\", $2 / 1024}'")); // RAM total 90 | line7.append("M/"); 91 | line7.append(GetStdoutFromCommand("sed -n '2p' /proc/meminfo | awk '{printf \"%.0f\\n\", $2/ 1024}'")); // RAM free 92 | line7.append("M"); 93 | oled.writeString(6, 0, (char*)line7.c_str()); 94 | 95 | string line8 = "HDD: "; 96 | line8.append(GetStdoutFromCommand("df -m | grep \"rootfs\" | awk '{print $2}'")); // HDD total 97 | line8.append("M/"); 98 | line8.append(GetStdoutFromCommand("df -m | grep \"rootfs\" | awk '{print $4}'")); // HDD total 99 | line8.append("M"); 100 | oled.writeString(7, 0, (char*)line8.c_str()); 101 | sleep(3); 102 | } 103 | 104 | return 0; 105 | } 106 | -------------------------------------------------------------------------------- /Grove - Digital_Light_Sensor/Digital_Light_TSL2561.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Digital_Light_TSL2561.h 3 | * A library for TSL2561 at RP 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : zhangkun 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | #include 33 | 34 | #ifndef __DIGITAL_LIGHT_TSL2561_H__ 35 | #define __DIGITAL_LIGHT_TSL2561_H__ 36 | 37 | #define TSL2561_CONTROL 0x80 38 | #define TSL2561_TIMING 0x81 39 | #define TSL2561_INTERRUPT 0x86 40 | #define TSL2561_CHANNAL0L 0x8C 41 | #define TSL2561_CHANNAL0H 0x8D 42 | #define TSL2561_CHANNAL1L 0x8E 43 | #define TSL2561_CHANNAL1H 0x8F 44 | 45 | //#define TSL2561_ADDRESS 0x29 //device address 46 | 47 | #define LUX_SCALE 14 // scale by 2^14 48 | #define RATIO_SCALE 9 // scale ratio by 2^9 49 | #define CH_SCALE 10 // scale channel values by 2^10 50 | #define CHSCALE_TINT0 0x7517 // 322/11 * 2^CH_SCALE 51 | #define CHSCALE_TINT1 0x0fe7 // 322/81 * 2^CH_SCALE 52 | 53 | #define K1T 0x0040 // 0.125 * 2^RATIO_SCALE 54 | #define B1T 0x01f2 // 0.0304 * 2^LUX_SCALE 55 | #define M1T 0x01be // 0.0272 * 2^LUX_SCALE 56 | #define K2T 0x0080 // 0.250 * 2^RATIO_SCA 57 | #define B2T 0x0214 // 0.0325 * 2^LUX_SCALE 58 | #define M2T 0x02d1 // 0.0440 * 2^LUX_SCALE 59 | #define K3T 0x00c0 // 0.375 * 2^RATIO_SCALE 60 | #define B3T 0x023f // 0.0351 * 2^LUX_SCALE 61 | #define M3T 0x037b // 0.0544 * 2^LUX_SCALE 62 | #define K4T 0x0100 // 0.50 * 2^RATIO_SCALE 63 | #define B4T 0x0270 // 0.0381 * 2^LUX_SCALE 64 | #define M4T 0x03fe // 0.0624 * 2^LUX_SCALE 65 | #define K5T 0x0138 // 0.61 * 2^RATIO_SCALE 66 | #define B5T 0x016f // 0.0224 * 2^LUX_SCALE 67 | #define M5T 0x01fc // 0.0310 * 2^LUX_SCALE 68 | #define K6T 0x019a // 0.80 * 2^RATIO_SCALE 69 | #define B6T 0x00d2 // 0.0128 * 2^LUX_SCALE 70 | #define M6T 0x00fb // 0.0153 * 2^LUX_SCALE 71 | #define K7T 0x029a // 1.3 * 2^RATIO_SCALE 72 | #define B7T 0x0018 // 0.00146 * 2^LUX_SCALE 73 | #define M7T 0x0012 // 0.00112 * 2^LUX_SCALE 74 | #define K8T 0x029a // 1.3 * 2^RATIO_SCALE 75 | #define B8T 0x0000 // 0.000 * 2^LUX_SCALE 76 | #define M8T 0x0000 // 0.000 * 2^LUX_SCALE 77 | 78 | 79 | 80 | #define K1C 0x0043 // 0.130 * 2^RATIO_SCALE 81 | #define B1C 0x0204 // 0.0315 * 2^LUX_SCALE 82 | #define M1C 0x01ad // 0.0262 * 2^LUX_SCALE 83 | #define K2C 0x0085 // 0.260 * 2^RATIO_SCALE 84 | #define B2C 0x0228 // 0.0337 * 2^LUX_SCALE 85 | #define M2C 0x02c1 // 0.0430 * 2^LUX_SCALE 86 | #define K3C 0x00c8 // 0.390 * 2^RATIO_SCALE 87 | #define B3C 0x0253 // 0.0363 * 2^LUX_SCALE 88 | #define M3C 0x0363 // 0.0529 * 2^LUX_SCALE 89 | #define K4C 0x010a // 0.520 * 2^RATIO_SCALE 90 | #define B4C 0x0282 // 0.0392 * 2^LUX_SCALE 91 | #define M4C 0x03df // 0.0605 * 2^LUX_SCALE 92 | #define K5C 0x014d // 0.65 * 2^RATIO_SCALE 93 | #define B5C 0x0177 // 0.0229 * 2^LUX_SCALE 94 | #define M5C 0x01dd // 0.0291 * 2^LUX_SCALE 95 | #define K6C 0x019a // 0.80 * 2^RATIO_SCALE 96 | #define B6C 0x0101 // 0.0157 * 2^LUX_SCALE 97 | #define M6C 0x0127 // 0.0180 * 2^LUX_SCALE 98 | #define K7C 0x029a // 1.3 * 2^RATIO_SCALE 99 | #define B7C 0x0037 // 0.00338 * 2^LUX_SCALE 100 | #define M7C 0x002b // 0.00260 * 2^LUX_SCALE 101 | #define K8C 0x029a // 1.3 * 2^RATIO_SCALE 102 | #define B8C 0x0000 // 0.000 * 2^LUX_SCALE 103 | #define M8C 0x0000 // 0.000 * 2^LUX_SCALE 104 | class Digital_Light_TSL2561 105 | { 106 | public: 107 | Digital_Light_TSL2561(uint16_t deviceAddress); 108 | virtual ~Digital_Light_TSL2561(); 109 | uint32_t calculateLux(uint16_t iGain, uint16_t tInt,uint16_t iType); 110 | void getLux(void); 111 | void init(void); 112 | uint16_t readRegister(uint16_t deviceAddress, uint16_t address); 113 | void writeRegister(uint16_t deviceAddress, uint16_t address, uint16_t val); 114 | private: 115 | uint16_t device_address; 116 | uint16_t CH0_LOW,CH0_HIGH,CH1_LOW,CH1_HIGH; 117 | uint32_t chScale; 118 | uint32_t channel1; 119 | uint32_t channel0; 120 | uint32_t ratio1; 121 | uint32_t b; 122 | uint32_t m; 123 | uint32_t temp; 124 | uint32_t lux; 125 | }; 126 | #endif 127 | -------------------------------------------------------------------------------- /Grove - OLED Display 128x64/font_16x24.h: -------------------------------------------------------------------------------- 1 | /* 2 | * font_16x24.h 3 | * A library for OLED Display 128*64 at RP 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : seeed fellow 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | #ifndef _FONT_16x24_H_ 32 | #define _FONT_16x24_H_ 33 | 34 | //----- DEFINES ----- 35 | #define FONT16x24_START 0x20 36 | #define FONT16x24_END 0x44 37 | #define FONT16x24_WIDTH 11 38 | #define FONT16x24_HEIGHT 24 39 | #define FONT16x24_BYTES 3 40 | 41 | //Used for displaying numbers 0 - 9 and '+', '-', '.' 42 | 43 | const uint8_t font_16x24[36][3][11] = 44 | { 45 | 46 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x20 47 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x21 48 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x22 49 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x23 50 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x24 51 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x25 52 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x26 53 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x27 54 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x28 55 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x29 56 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x2A 57 | 58 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,64,64,64,254,254,64,64} , {0,0,0,0,0,0,0,15,15,0,0}} ,// '+'// 0x2B 59 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// // 0x2C 60 | 61 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,64,64,64,64,64,64,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// '-'// 0x2D 62 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,60,60,60,0,0,0,0,0}} ,// '.'// 0x2E 63 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x2F 64 | 65 | {{0,128,192,224,224,96,224,224,192,128,0} , {112,255,255,1,0,0,0,0,255,255,254} , {0,15,31,60,56,48,56,56,31,15,3}} , //'0' 0x30 66 | {{0,0,0,0,128,224,224,0,0,0,0} , {0,0,3,3,3,255,255,0,0,0,0} , {0,0,56,56,56,63,63,56,56,56,0}} , //'1' 0x31 67 | {{0,192,192,224,96,96,224,224,192,128,0} , {0,1,0,0,128,192,224,249,63,31,0} , {0,60,62,63,63,59,57,56,56,56,56}} , //'2' 0x32 68 | {{0,192,224,224,96,96,224,224,192,192,0} , {0,1,0,0,48,48,56,125,239,207,0} , {0,28,56,56,48,48,56,60,31,15,1}} , //'3' 0x33 69 | {{0,0,0,0,0,128,192,224,224,0,0} , {224,240,248,222,207,199,193,255,255,192,192} , {0,0,0,0,0,0,0,63,63,0,0}} , //'4' 0x34 70 | {{0,224,224,224,224,224,224,224,224,224,224} , {0,63,63,63,56,56,48,112,240,224,0} , {0,28,56,56,48,48,56,60,31,15,1}} , //'5' 0x35 71 | {{0,0,128,192,192,224,96,96,224,224,0} , {224,254,255,55,57,24,24,56,240,240,192} , {0,15,31,28,56,48,48,56,31,15,7}} , //'6' 0x36 72 | {{0,224,224,224,224,224,224,224,224,224,224} , {0,0,0,0,128,224,248,126,31,7,1} , {0,0,56,62,31,7,1,0,0,0,0}} , //'7' 0x37 73 | {{0,128,192,224,224,96,96,224,192,192,0} , {0,207,255,127,56,48,112,112,255,239,199} , {3,15,31,60,56,48,48,56,31,31,15}} , //'8' 0x38 74 | {{0,128,192,224,224,96,224,224,192,128,0} , {12,63,127,241,224,192,192,225,255,255,254} , {0,0,56,48,48,56,56,30,15,7,0}} , //'9' 0x39 75 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x3A 76 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x3B 77 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x3C 78 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x3D 79 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x3E 80 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x3F 81 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x40 82 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x41 83 | {{0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0} , {0,0,0,0,0,0,0,0,0,0,0}} ,// 0x42 84 | {{0,128,192,224,224,96,224,224,192,128,0} , {112,112,112,1,0,0,0,0,112,112,112} , {0,0,0,0,0,0,0,0,0,0,0}} //'C' 0x43 85 | }; 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /Grove - OLED Display 128x64/font_8x8.h: -------------------------------------------------------------------------------- 1 | /* 2 | * font_8x8.h 3 | * A library for OLED Display 128*64 at RP 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : seeed fellow 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | #ifndef _FONT_8x8_H_ 33 | #define _FONT_8x8_H_ 34 | 35 | 36 | //----- DEFINES ----- 37 | #define FONT8x8_START 0x20 38 | //#define FONT8x8_END 0x44 39 | #define FONT8x8_WIDTH 8 40 | #define FONT8x8_HEIGHT 8 41 | #define FONT8x8_BYTES 1 42 | 43 | //======================== 44 | const uint8_t font_8x8[][8] = { 45 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 46 | {0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00}, 47 | {0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00}, 48 | {0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00}, 49 | {0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00}, 50 | {0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00}, 51 | {0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00}, 52 | {0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00}, 53 | {0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00}, 54 | {0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00}, 55 | {0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00}, 56 | {0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00}, 57 | {0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00}, 58 | {0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00}, 59 | {0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00}, 60 | {0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00}, 61 | {0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00}, 62 | {0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00}, 63 | {0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00}, 64 | {0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00}, 65 | {0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00}, 66 | {0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00}, 67 | {0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00}, 68 | {0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00}, 69 | {0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00}, 70 | {0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00}, 71 | {0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00}, 72 | {0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00}, 73 | {0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00}, 74 | {0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00}, 75 | {0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00}, 76 | {0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00}, 77 | {0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00}, 78 | {0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00}, 79 | {0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00}, 80 | {0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00}, 81 | {0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00}, 82 | {0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00}, 83 | {0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00}, 84 | {0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00}, 85 | {0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00}, 86 | {0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00}, 87 | {0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00}, 88 | {0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00}, 89 | {0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00}, 90 | {0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00}, 91 | {0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00}, 92 | {0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00}, 93 | {0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00}, 94 | {0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00}, 95 | {0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00}, 96 | {0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00}, 97 | {0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00}, 98 | {0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00}, 99 | {0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00}, 100 | {0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00}, 101 | {0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00}, 102 | {0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00}, 103 | {0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00}, 104 | {0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00}, 105 | {0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00}, 106 | {0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00}, 107 | {0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00}, 108 | {0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00}, 109 | {0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00}, 110 | {0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00}, 111 | {0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00}, 112 | {0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00}, 113 | {0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00}, 114 | {0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00}, 115 | {0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00}, 116 | {0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00}, 117 | {0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00}, 118 | {0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00}, 119 | {0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00}, 120 | {0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00}, 121 | {0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00}, 122 | {0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00}, 123 | {0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00}, 124 | {0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00}, 125 | {0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00}, 126 | {0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00}, 127 | {0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00}, 128 | {0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00}, 129 | {0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00}, 130 | {0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00}, 131 | {0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00}, 132 | {0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00}, 133 | {0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00}, 134 | {0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00}, 135 | {0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00}, 136 | {0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00}, 137 | {0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00}, 138 | {0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00}, 139 | {0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00}, 140 | {0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00} 141 | }; 142 | 143 | #endif // include -------------------------------------------------------------------------------- /Grove - Digital_Light_Sensor/Digital_Light_TSL2561.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Digital_Light_TSL2561.cpp 3 | * A library for TSL2561 at RP 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : zhangkun 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #include "Digital_Light_TSL2561.h" 46 | 47 | Digital_Light_TSL2561::Digital_Light_TSL2561(uint16_t deviceAddress) 48 | { 49 | device_address = deviceAddress; 50 | init(); 51 | } 52 | 53 | Digital_Light_TSL2561::~Digital_Light_TSL2561() 54 | { 55 | 56 | } 57 | 58 | uint16_t Digital_Light_TSL2561::readRegister(uint16_t deviceAddress, uint16_t address) 59 | { 60 | uint16_t value; 61 | int file; 62 | uint16_t buf[1] = {address}; 63 | uint16_t reBuf[1] = {0}; 64 | 65 | if ( (file = open("/dev/i2c-1", O_RDWR)) < 0 ) { 66 | printf("Failed to open the bus."); 67 | } 68 | 69 | if(ioctl(file,I2C_SLAVE,deviceAddress) < 0) { 70 | printf("Failed to acquire bus access and/or talk to slave.\n"); 71 | } 72 | 73 | /* send the register address which want read */ 74 | write(file, buf, 1); 75 | read(file, reBuf, 1); 76 | 77 | close(file); 78 | return reBuf[0]; 79 | } 80 | 81 | void Digital_Light_TSL2561::writeRegister(uint16_t deviceAddress, uint16_t address, uint16_t val) 82 | { 83 | int file; // fd 84 | char buf[2] = {0}; // buffer for write. 85 | 86 | /* open the i2c dev */ 87 | if((file = open("/dev/i2c-1",O_RDWR)) < 0) { 88 | printf("Failed to open the bus."); 89 | } 90 | 91 | if(ioctl(file,I2C_SLAVE,deviceAddress) < 0) { 92 | printf("Failed to acquire bus access and/or talk to slave.\n"); 93 | } 94 | 95 | buf[0] = (char)address; 96 | buf[1] = (char)val; 97 | 98 | // printf("Write Register\n"); 99 | // printf("address %d, val %d \n", &address, &val); 100 | 101 | write(file,buf,2); 102 | close(file); 103 | } 104 | void Digital_Light_TSL2561::getLux(void) 105 | { 106 | CH0_LOW=readRegister(device_address,TSL2561_CHANNAL0L); 107 | CH0_HIGH=readRegister(device_address,TSL2561_CHANNAL0H); 108 | //read two bytes from registers 0x0E and 0x0F 109 | CH1_LOW=readRegister(device_address,TSL2561_CHANNAL1L); 110 | CH1_HIGH=readRegister(device_address,TSL2561_CHANNAL1H); 111 | 112 | channel0=CH0_HIGH*256+CH0_LOW; 113 | channel1=CH1_HIGH*256+CH1_LOW; 114 | } 115 | void Digital_Light_TSL2561::init() 116 | { 117 | writeRegister(device_address,TSL2561_CONTROL,0x03); // POWER UP 118 | writeRegister(device_address,TSL2561_TIMING,0x11); //High Gain (16x), integration time of 101ms 119 | writeRegister(device_address,TSL2561_INTERRUPT,0x00); 120 | } 121 | 122 | uint32_t Digital_Light_TSL2561::calculateLux(uint16_t iGain, uint16_t tInt, uint16_t iType) 123 | { 124 | switch (tInt) 125 | { 126 | case 0: // 13.7 msec 127 | chScale = CHSCALE_TINT0; 128 | break; 129 | case 1: // 101 msec 130 | chScale = CHSCALE_TINT1; 131 | break; 132 | default: // assume no scaling 133 | chScale = (1 << CH_SCALE); 134 | break; 135 | } 136 | if (!iGain) chScale = chScale << 4; // scale 1X to 16X 137 | // scale the channel values 138 | channel0 = (channel0 * chScale) >> CH_SCALE; 139 | channel1 = (channel1 * chScale) >> CH_SCALE; 140 | 141 | ratio1 = 0; 142 | if (channel0!= 0) ratio1 = (channel1 << (RATIO_SCALE+1))/channel0; 143 | // round the ratio value 144 | uint16_t ratio = (ratio1 + 1) >> 1; 145 | 146 | switch (iType) 147 | { 148 | case 0: // T package 149 | if ((ratio >= 0) && (ratio <= K1T)) 150 | {b=B1T; m=M1T;} 151 | else if (ratio <= K2T) 152 | {b=B2T; m=M2T;} 153 | else if (ratio <= K3T) 154 | {b=B3T; m=M3T;} 155 | else if (ratio <= K4T) 156 | {b=B4T; m=M4T;} 157 | else if (ratio <= K5T) 158 | {b=B5T; m=M5T;} 159 | else if (ratio <= K6T) 160 | {b=B6T; m=M6T;} 161 | else if (ratio <= K7T) 162 | {b=B7T; m=M7T;} 163 | else if (ratio > K8T) 164 | {b=B8T; m=M8T;} 165 | break; 166 | case 1:// CS package 167 | if ((ratio >= 0) && (ratio <= K1C)) 168 | {b=B1C; m=M1C;} 169 | else if (ratio <= K2C) 170 | {b=B2C; m=M2C;} 171 | else if (ratio <= K3C) 172 | {b=B3C; m=M3C;} 173 | else if (ratio <= K4C) 174 | {b=B4C; m=M4C;} 175 | else if (ratio <= K5C) 176 | {b=B5C; m=M5C;} 177 | else if (ratio <= K6C) 178 | {b=B6C; m=M6C;} 179 | else if (ratio <= K7C) 180 | {b=B7C; m=M7C;} 181 | } 182 | temp=((channel0*b)-(channel1*m)); 183 | if(temp<0) temp=0; 184 | temp+=(1<>LUX_SCALE; 187 | return (lux); 188 | } 189 | -------------------------------------------------------------------------------- /Grove - Temperature and Humidity Sensor Pro/dht22.c: -------------------------------------------------------------------------------- 1 | /* 2 | * dht22.c 3 | * A library for Grove - Temperature and Humidity Sensor Pro at RP 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : technion@lolware.net, yexiaobo@seeedstudio.com 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "locking.h" 42 | 43 | #define MAXTIMINGS 85 44 | static int dht22_dat[5] = {0,0,0,0,0}; 45 | 46 | static void PrintUsage() 47 | { 48 | printf ("ReadDHT22 \n"); 49 | printf (" pin : GPIO No (0-7)\n"); 50 | printf (" mode : V - verbose output\n"); 51 | printf (" S - simple output.\n"); 52 | printf (" [-]HHH\n"); 53 | printf (" [-]TTT\n"); 54 | printf (" Values are signed 16 bit resolution and need dividing by 10\n"); 55 | } 56 | 57 | static uint8_t sizecvt(const int read) 58 | { 59 | /* digitalRead() and friends from wiringpi are defined as returning a value 60 | < 256. However, they are returned as int() types. This is a safety function */ 61 | 62 | if (read > 255 || read < 0) 63 | { 64 | printf("Invalid data from wiringPi library\n"); 65 | exit(EXIT_FAILURE); 66 | } 67 | return (uint8_t)read; 68 | } 69 | 70 | static int read_dht22_dat(int iPin, int* piHumidity, int* piTemp) 71 | { 72 | uint8_t laststate = HIGH; 73 | uint8_t counter = 0; 74 | uint8_t j = 0, i; 75 | 76 | dht22_dat[0] = dht22_dat[1] = dht22_dat[2] = dht22_dat[3] = dht22_dat[4] = 0; 77 | 78 | // pull pin down for 18 milliseconds 79 | pinMode(iPin, OUTPUT); 80 | digitalWrite(iPin, LOW); 81 | delay(18); 82 | 83 | // then pull it up for 40 microseconds 84 | digitalWrite(iPin, HIGH); 85 | delayMicroseconds(40); 86 | 87 | // prepare to read the pin 88 | pinMode(iPin, INPUT); 89 | 90 | // detect change and read data 91 | for ( i=0; i< MAXTIMINGS; i++) 92 | { 93 | counter = 0; 94 | while (sizecvt(digitalRead(iPin)) == laststate) 95 | { 96 | counter++; 97 | delayMicroseconds(1); 98 | if (counter == 255) 99 | { 100 | break; 101 | } 102 | } 103 | laststate = sizecvt(digitalRead(iPin)); 104 | 105 | if (counter == 255) break; 106 | 107 | // ignore first 3 transitions 108 | if ((i >= 4) && (i%2 == 0)) 109 | { 110 | // shove each bit into the storage bytes 111 | dht22_dat[j/8] <<= 1; 112 | if (counter > 16) 113 | dht22_dat[j/8] |= 1; 114 | j++; 115 | } 116 | } 117 | 118 | // check we read 40 bits (8bit x 5 ) + verify checksum in the last byte 119 | // print it out if data is good 120 | if ((j >= 40) && (dht22_dat[4] == ((dht22_dat[0] + dht22_dat[1] + dht22_dat[2] + dht22_dat[3]) & 0xFF)) ) 121 | { 122 | *piHumidity = dht22_dat[0] * 256 + dht22_dat[1]; 123 | *piTemp = (dht22_dat[2] & 0x7F)* 256 + dht22_dat[3]; 124 | if ((dht22_dat[2] & 0x80) != 0) 125 | *piTemp *= -1; 126 | 127 | return 1; 128 | } 129 | else 130 | { 131 | return 0; 132 | } 133 | } 134 | 135 | int main( int argc, char * argv[]) 136 | { 137 | int lockfd; 138 | int iPin = 0; 139 | int iErr = 0; 140 | char cMode = 'V'; 141 | int iReturnCode = 0; 142 | 143 | if ( argc !=3 ) 144 | { 145 | PrintUsage(); 146 | return -1; 147 | } 148 | 149 | if (strlen(argv[1]) != 1 || argv[1][0] < '0' || argv[1][0] > '7') 150 | { 151 | PrintUsage(); 152 | printf ("Invalid Pin Value [%s]\n", argv[1]); 153 | return -1; 154 | } 155 | if (strlen(argv[2]) != 1 || (argv[2][0] != 'V' && argv[2][0] != 'S')) 156 | { 157 | PrintUsage(); 158 | printf ("Invalid Mode Value [%s]\n", argv[2]); 159 | return -1; 160 | } 161 | 162 | iPin = atoi(argv[1]); 163 | cMode = argv[2][0]; 164 | 165 | if (cMode == 'V') 166 | { 167 | printf ("Raspberry Pi wiringPi DHT22 reader\n"); 168 | printf (" Reading data from pin %d\n", iPin); 169 | } 170 | 171 | lockfd = open_lockfile(LOCKFILE); 172 | 173 | iErr = wiringPiSetup (); 174 | if (iErr == -1) 175 | { 176 | if (cMode == 'V') 177 | printf ("ERROR : Failed to init WiringPi %d\n", iErr); 178 | iReturnCode = -1; 179 | } 180 | else 181 | { 182 | if (setuid(getuid()) < 0) 183 | { 184 | perror("Dropping privileges failed\n"); 185 | iReturnCode = -1; 186 | } 187 | else 188 | { 189 | int iHumidity = -1; 190 | int iTemp = -1; 191 | 192 | for(int i = 0; i<10; i++) 193 | { 194 | // read_dht22_dat(iPin); 195 | if (read_dht22_dat(iPin, &iHumidity, &iTemp) == 1) 196 | { 197 | if (cMode == 'V') 198 | printf(" Humidity = %.2f %% Temperature = %.2f *C \n", (float)(iHumidity/10.0), (float)(iTemp/10.0) ); 199 | else 200 | printf("%d\n%d\n", iHumidity, iTemp); 201 | iReturnCode = 0; 202 | break; 203 | } 204 | else 205 | { 206 | if (cMode == 'V') 207 | { 208 | printf(" Data not good, skip\n"); 209 | iReturnCode = -1; 210 | } 211 | } 212 | } 213 | } 214 | } 215 | 216 | close_lockfile(lockfd); 217 | 218 | return iReturnCode; 219 | } 220 | 221 | 222 | -------------------------------------------------------------------------------- /Grove - Barometer_Sensor/Barometer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Barometer.cpp 3 | * A library for barometer at RP 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : LG 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include "Barometer.h" 47 | 48 | Barometer::Barometer(){ 49 | init(); 50 | } 51 | 52 | Barometer::~Barometer(){ 53 | } 54 | 55 | void Barometer::init(void) 56 | { 57 | ac1 = bmp085ReadInt(0xAA); 58 | ac2 = bmp085ReadInt(0xAC); 59 | ac3 = bmp085ReadInt(0xAE); 60 | ac4 = bmp085ReadInt(0xB0); 61 | ac5 = bmp085ReadInt(0xB2); 62 | ac6 = bmp085ReadInt(0xB4); 63 | b1 = bmp085ReadInt(0xB6); 64 | b2 = bmp085ReadInt(0xB8); 65 | mb = bmp085ReadInt(0xBA); 66 | mc = bmp085ReadInt(0xBC); 67 | md = bmp085ReadInt(0xBE); 68 | } 69 | // Read 1 unsigned charfrom the BMP085 at 'address' 70 | // Return: the read byte; 71 | char Barometer::bmp085Read(unsigned char address) 72 | { 73 | int file; 74 | unsigned char buf[1] = {address}; 75 | char reBuf[1] = {0}; 76 | 77 | /* open the i2c dev */ 78 | if((file = open("/dev/i2c-1",O_RDWR)) < 0) { 79 | printf("Failed to open the bus."); 80 | } 81 | 82 | if(ioctl(file,I2C_SLAVE,BMP085_ADDRESS) < 0) { 83 | printf("Failed to acquire bus access and/or talk to slave.\n"); 84 | } 85 | write(file,buf,1); 86 | while(0 == reBuf[0]) { 87 | read(file,reBuf,1); 88 | } 89 | close(file); 90 | 91 | return reBuf[0]; 92 | } 93 | // Read 2 bytes from the BMP085 94 | // First unsigned charwill be from 'address' 95 | // Second unsigned charwill be from 'address'+1 96 | int16_t Barometer::bmp085ReadInt(unsigned char address) 97 | { 98 | int file; 99 | unsigned char msb, lsb; 100 | unsigned char buf[1] = {address}; 101 | unsigned char reBuf[2] = {0,0}; 102 | 103 | /* open the i2c dev */ 104 | if((file = open("/dev/i2c-1",O_RDWR)) < 0) { 105 | printf("Failed to open the bus."); 106 | } 107 | 108 | if(ioctl(file,I2C_SLAVE,BMP085_ADDRESS) < 0) { 109 | printf("Failed to acquire bus access and/or talk to slave.\n"); 110 | } 111 | 112 | write(file,buf,1); 113 | read(file,reBuf, 2); 114 | msb = reBuf[0]; 115 | lsb = reBuf[1]; 116 | close(file); 117 | 118 | return (int16_t) msb<<8 | lsb; 119 | } 120 | // Read the uncompensated temperature value 121 | uint16_t Barometer::bmp085ReadUT() 122 | { 123 | uint16_t ut; 124 | int file; 125 | unsigned char buf[2] = {0xF4,0x2E}; 126 | 127 | /* open the i2c dev */ 128 | if((file = open("/dev/i2c-1",O_RDWR)) < 0) { 129 | printf("Failed to open the bus."); 130 | } 131 | 132 | if(ioctl(file,I2C_SLAVE,BMP085_ADDRESS) < 0) { 133 | printf("Failed to acquire bus access and/or talk to slave.\n"); 134 | } 135 | 136 | write(file,buf,2); 137 | close(file); 138 | sleep(1); 139 | 140 | ut = bmp085ReadInt(0xF6); 141 | return ut; 142 | } 143 | // Read the uncompensated pressure value 144 | unsigned long Barometer::bmp085ReadUP() 145 | { 146 | unsigned char msb, lsb, xlsb; 147 | unsigned long up = 0; 148 | int file; 149 | unsigned char a = 0x34 + (OSS<<6); 150 | unsigned char buf[2] = {0xF4,a}; 151 | 152 | /* open the i2c dev */ 153 | if((file = open("/dev/i2c-1",O_RDWR)) < 0) { 154 | printf("Failed to open the bus."); 155 | } 156 | 157 | if(ioctl(file,I2C_SLAVE,BMP085_ADDRESS) < 0) { 158 | printf("Failed to acquire bus access and/or talk to slave.\n"); 159 | } 160 | write(file,buf,2); 161 | close(file); 162 | sleep(2 + (3<> (8-OSS); 169 | return up; 170 | } 171 | void Barometer::writeRegister(int16_t deviceAddress, unsigned char address, unsigned char val) 172 | { 173 | int file; 174 | unsigned char buf[2] = {address, val}; 175 | 176 | /* open the i2c dev */ 177 | if((file = open("/dev/i2c-1",O_RDWR)) < 0) { 178 | printf("Failed to open the bus."); 179 | } 180 | 181 | if(ioctl(file,I2C_SLAVE,deviceAddress) < 0) { 182 | printf("Failed to acquire bus access and/or talk to slave.\n"); 183 | } 184 | write(file,buf,2); 185 | close(file); 186 | } 187 | int16_t Barometer::readRegister(int16_t deviceAddress, unsigned char address) 188 | { 189 | int file; 190 | unsigned char buf[1] = {address}; 191 | int16_t reBuf[1] = {0}; 192 | 193 | /* open the i2c dev */ 194 | if((file = open("/dev/i2c-1",O_RDWR)) < 0) { 195 | printf("Failed to open the bus."); 196 | } 197 | 198 | if(ioctl(file,I2C_SLAVE,deviceAddress) < 0) { 199 | printf("Failed to acquire bus access and/or talk to slave.\n"); 200 | } 201 | write(file,buf,1); 202 | while(0 == reBuf[0]) { 203 | read(file,reBuf,1); 204 | } 205 | close(file); 206 | 207 | return reBuf[0]; 208 | } 209 | float Barometer::calcAltitude(float pressure) 210 | { 211 | float A = pressure/101325; 212 | float B = 1/5.25588; 213 | float C = pow(A,B); 214 | //printf("c = pow(a,b) = %d \n", &C); 215 | C = 1 - C; 216 | C = C /0.0000225577; 217 | return C; 218 | } 219 | float Barometer::bmp085GetTemperature(uint16_t ut) 220 | { 221 | long x1, x2; 222 | 223 | x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15; 224 | x2 = ((long)mc << 11)/(x1 + md); 225 | PressureCompensate = x1 + x2; 226 | 227 | float temp = ((PressureCompensate + 8)>>4); 228 | temp = temp /10; 229 | 230 | return temp; 231 | } 232 | long Barometer::bmp085GetPressure(unsigned long up) 233 | { 234 | long x1, x2, x3, b3, b6, p; 235 | unsigned long b4, b7; 236 | b6 = PressureCompensate - 4000; 237 | x1 = (b2 * (b6 * b6)>>12)>>11; 238 | x2 = (ac2 * b6)>>11; 239 | x3 = x1 + x2; 240 | b3 = (((((long)ac1)*4 + x3)<>2; 241 | 242 | // Calculate B4 243 | x1 = (ac3 * b6)>>13; 244 | x2 = (b1 * ((b6 * b6)>>12))>>16; 245 | x3 = ((x1 + x2) + 2)>>2; 246 | b4 = (ac4 * (unsigned long)(x3 + 32768))>>15; 247 | 248 | b7 = ((unsigned long)(up - b3) * (50000>>OSS)); 249 | if (b7 < 0x80000000) 250 | p = (b7<<1)/b4; 251 | else 252 | p = (b7/b4)<<1; 253 | 254 | x1 = (p>>8) * (p>>8); 255 | x1 = (x1 * 3038)>>16; 256 | x2 = (-7357 * p)>>16; 257 | p += (x1 + x2 + 3791)>>4; 258 | 259 | long temp = p; 260 | return temp; 261 | } 262 | -------------------------------------------------------------------------------- /Grove - OLED Display 128x64/SeeedOLED.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SeeedOLED.h 3 | * A library for OLED Display 128*64 at RP 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : seeed fellow 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | #ifndef SEEEDOLED_H 32 | #define SEEEDOLED_H 33 | 34 | #include 35 | 36 | // This is the I2C address (8 bit) 37 | // There are two possible addresses: with D/C# (pin 13) grounded, the address is 0x78, 38 | // with D/C# tied high it is 0x7A. Assume grounded by default. 39 | 40 | // I2C Slave Address bit "0111 10 SA0 R/W" --> "0x7x" 41 | #define SSD1308_SA0 0x3C // 0011 1100 42 | #define SSD1308_SA1 0x3D // 0011 1101 43 | #define SSD1308_DEF_SA SSD1308_SA0 44 | 45 | // Display dimensions 46 | #define ROWS 64 // Row of the OLED 47 | #define COLUMNS 128 // Colume of the OLED 48 | #define PAGES (ROWS / 8) // 0-7 pages 49 | #define MAX_PAGE (PAGES - 1) 50 | #define MAX_ROW (ROWS - 1) //0-63 51 | #define MAX_COL (COLUMNS - 1) // 0-127 52 | 53 | // Character dimensions 8x8 font 54 | #define CHARS (COLUMNS / FONT8x8_WIDTH) 55 | 56 | // Command and Datamode 57 | #define COMMAND_MODE 0x80 // continuation bit is set! 58 | #define DATA_MODE 0x40 59 | 60 | // Commands and Parameter defines 61 | #define SET_LOWER_COLUMN 0x00 // | with lower nibble (Page mode only) 62 | #define SET_HIGHER_COLUMN 0x10 // | with higher nibble (Page mode only) 63 | 64 | #define HORIZONTAL_ADDRESSING_MODE 0x00 65 | #define VERTICAL_ADDRESSING_MODE 0x01 66 | #define PAGE_ADDRESSING_MODE 0x02 67 | #define SET_MEMORY_ADDRESSING_MODE 0x20 // takes one byte as given above 68 | 69 | #define SET_COLUMN_ADDRESS 0x21 // takes two bytes, start address and end address of display data RAM 70 | #define SET_PAGE_ADDRESS 0x22 // takes two bytes, start address and end address of display data RAM 71 | 72 | // Command maybe unsupported by SSD1308 73 | #define FADE_INTERVAL_8_FRAMES 0x00 74 | #define FADE_INTERVAL_16_FRAMES 0x01 75 | #define FADE_INTERVAL_24_FRAMES 0x02 76 | #define FADE_INTERVAL_32_FRAMES 0x03 77 | #define FADE_INTERVAL_64_FRAMES 0x07 78 | #define FADE_INTERVAL_128_FRAMES 0x0F 79 | #define FADE_BLINK_DISABLE 0x00 80 | #define FADE_OUT_ENABLE 0x20 81 | #define BLINK_ENABLE 0x30 82 | #define SET_FADE_BLINK 0x23 // takes one byte 83 | // bit5-4 = 0, fade/blink mode 84 | // bit3-0 = Time interval in frames 85 | 86 | #define SET_DISPLAY_START_LINE 0x40 // | with a row number 0-63 to set start row. (Reset = 0) 87 | 88 | #define SET_CONTRAST 0x81 // takes one byte, 0x00 - 0xFF 89 | 90 | #define SET_SEGMENT_REMAP_0 0xA0 // column address 0 is mapped to SEG0 (Reset) 91 | #define SET_SEGMENT_REMAP_127 0xA1 // column address 127 is mapped to SEG0 92 | 93 | #define SET_DISPLAY_GDDRAM 0xA4 // restores display to contents of RAM 94 | #define SET_ENTIRE_DISPLAY_ON 0xA5 // turns all pixels on, does not affect RAM 95 | 96 | #define SET_NORMAL_DISPLAY 0xA6 // a databit of 1 indicates pixel 'ON' 97 | #define SET_INVERSE_DISPLAY 0xA7 // a databit of 1 indicates pixel 'OFF' 98 | 99 | #define SET_MULTIPLEX_RATIO 0xA8 // takes one byte, from 16xMUX to 64xMUX (MUX Ratio = byte+1; Default 64) 100 | 101 | #define EXTERNAL_IREF 0x10 102 | #define INTERNAL_IREF 0x00 103 | #define SET_IREF_SELECTION 0xAD // sets internal or external Iref 104 | 105 | #define SET_DISPLAY_POWER_OFF 0xAE 106 | #define SET_DISPLAY_POWER_ON 0xAF 107 | 108 | #define PAGE0 0x00 109 | #define PAGE1 0x01 110 | #define PAGE2 0x02 111 | #define PAGE3 0x03 112 | #define PAGE4 0x04 113 | #define PAGE5 0x05 114 | #define PAGE6 0x06 115 | #define PAGE7 0x07 116 | #define SET_PAGE_START_ADDRESS 0xB0 // | with a page number to get start address (Page mode only) 117 | 118 | #define SET_COMMON_REMAP_0 0xC0 // row address 0 is mapped to COM0 (Reset) 119 | #define SET_COMMON_REMAP_63 0xC8 // row address 63 is mapped to COM0 120 | 121 | #define SET_DISPLAY_OFFSET 0xD3 // takes one byte from 0-63 for vertical shift, Reset = 0 122 | 123 | #define SET_DISPLAY_CLOCK 0xD5 // takes one byte 124 | // bit7-4 = Osc Freq DCLK (Reset = 1000b) 125 | // bit3-0 = Divide ration (Reset = oooob, Ratio = 1) 126 | 127 | #define SET_PRECHARGE_TIME 0xD9 // takes one byte 128 | // bit7-4 = Phase2, upto 15 DCLKs (Reset = 0010b) 129 | // bit3-0 = Phase1, upto 15 DCLKs (Reset = 0010b) 130 | 131 | 132 | #define COMMON_BASE 0x02 // 133 | #define COMMON_SEQUENTIAL 0x00 // Sequential common pins config 134 | #define COMMON_ALTERNATIVE 0x10 // Odd/Even common pins config (Reset) 135 | #define COMMON_LEFTRIGHT_NORMAL 0x00 // LeftRight Normal (Reset) 136 | #define COMMON_LEFTRIGHT_FLIP 0x20 // LeftRight Flip 137 | #define SET_COMMON_CONF 0xDA // takes one byte as given above 138 | 139 | 140 | #define VCOMH_DESELECT_0_65_CODE 0x00 141 | #define VCOMH_DESELECT_0_77_CODE 0x20 142 | #define VCOMH_DESELECT_0_83_CODE 0x30 143 | #define SET_VCOMH_DESELECT_LEVEL 0xDB // takes one byte as given above 144 | 145 | #define NOP 0xE3 146 | 147 | #define SCROLL_INTERVAL_5_FRAMES 0x00 148 | #define SCROLL_INTERVAL_64_FRAMES 0x01 149 | #define SCROLL_INTERVAL_128_FRAMES 0x02 150 | #define SCROLL_INTERVAL_256_FRAMES 0x03 151 | #define SCROLL_INTERVAL_3_FRAMES 0x04 152 | #define SCROLL_INTERVAL_4_FRAMES 0x05 153 | #define SCROLL_INTERVAL_25_FRAMES 0x06 154 | #define SCROLL_INTERVAL_2_FRAMES 0x07 155 | 156 | #define SET_RIGHT_HOR_SCROLL 0x26 // takes 6 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, 0x00, 0xFF 157 | #define SET_LEFT_HOR_SCROLL 0x27 // takes 6 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, 0x00, 0xFF 158 | 159 | #define SET_VERT_RIGHT_HOR_SCROLL 0x29 // takes 5 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, VertOffset 160 | #define SET_VERT_LEFT_HOR_SCROLL 0x2A // takes 5 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, VertOffset 161 | 162 | #define SET_DEACTIVATE_SCROLL 0x2E 163 | #define SET_ACTIVATE_SCROLL 0x2F 164 | 165 | #define SET_VERTICAL_SCROLL_AREA 0xA3 // takes 2 bytes: Rows in Top Area (Reset=0), Rows in Scroll Area (Reset=64) 166 | 167 | class SeeedOLED 168 | { 169 | public: 170 | SeeedOLED(uint8_t deviceAddress); 171 | virtual ~SeeedOLED(); 172 | void initialize(); 173 | void clearDisplay(); 174 | void fillDisplay(uint8_t pattern = 0x00, uint8_t start_page=0, uint8_t end_page=MAX_PAGE, uint8_t start_col=0, uint8_t end_col=MAX_COL); 175 | void writeBitmap(uint8_t* data, uint8_t start_page=0, uint8_t end_page=MAX_PAGE, uint8_t start_col=0, uint8_t end_col=MAX_COL); 176 | void writeProgressBar(uint8_t page, uint8_t col, int percentage); 177 | void writeLevelBar(uint8_t page, uint8_t col, int percentage); 178 | //void setXY(uint8_t, uint8_t y); 179 | void setInverted(bool inverted) { _inverted = inverted; }; 180 | void writeChar(char chr); 181 | void writeBigChar(uint8_t row, uint8_t col, char chr); 182 | void writeString(uint8_t row, uint8_t col, const char* txt); 183 | virtual int _putc(int value) { writeChar(value); return 1; }; 184 | virtual int _getc() { return -1; }; 185 | void setHorizontalAddressingMode(); 186 | void setVerticalAddressingMode(); 187 | void setPageAddressingMode(); 188 | void setMemoryAddressingMode(uint8_t mode); 189 | void setColumnStartForPageAddressingMode(uint8_t column); 190 | void setPageStartForPageAddressingMode(uint8_t page); 191 | void setColumnAddress(uint8_t start, uint8_t end); 192 | void setPageAddress(uint8_t start, uint8_t end); 193 | void setDisplayStartLine(uint8_t line); 194 | void setContrastControl(uint8_t contrast); 195 | void setEntireDisplayOn(); 196 | void setEntireDisplayRAM(); 197 | void setEntireDisplay(bool on); 198 | void setMultiplexRatio(uint8_t lines); 199 | void setInternalIref(); 200 | void setExternalIref(); 201 | void setDisplayOn(); 202 | void setDisplayOff(); 203 | void setDisplayPower(bool on); 204 | void setDisplayNormal(); 205 | void setDisplayInverse(); 206 | void setDisplayBlink(bool on); 207 | void setDisplayFade(bool on); 208 | void setDisplayFlip(bool left, bool down); 209 | void setDisplayOffset(uint8_t offset); 210 | void setDisplayClock(uint8_t divideRatio, uint8_t oscFreq); 211 | void setPrechargePeriod(uint8_t phase1, uint8_t phase2); 212 | void setVcomhDeselectLevel(uint8_t level); 213 | void nop(); 214 | void setContinuousHorizontalScroll(bool left, uint8_t start_page, uint8_t end_page, uint8_t interval); 215 | void setContinuousVerticalAndHorizontalScroll(bool left, uint8_t start_page, uint8_t end_page, 216 | uint8_t offset, uint8_t interval); 217 | void setDisplayScroll(bool on); 218 | void setVerticalScrollArea(uint8_t topRowsFixed, uint8_t scrollRows); 219 | private: 220 | void _sendCommand(uint8_t command); 221 | void _sendCommand(uint8_t command, uint8_t param1); 222 | void _sendCommand(uint8_t command, uint8_t param1, uint8_t param2); 223 | //void sendCommands(uint8_t len, uint8_t* buf); 224 | void _sendCommand(uint8_t command, uint8_t param1, uint8_t param2, 225 | uint8_t param3, uint8_t param4, 226 | uint8_t param5); 227 | void _sendCommand(uint8_t command, uint8_t param1, uint8_t param2, 228 | uint8_t param3, uint8_t param4, 229 | uint8_t param5, uint8_t param6); 230 | void _sendData(uint8_t data); 231 | void _sendData(uint8_t len, uint8_t* data); 232 | void _init(); 233 | uint8_t _readOpcode; // contains the I2C address of the device 234 | uint8_t _writeOpcode; // contains the I2C address of the device 235 | bool _inverted; // inverted or normal text 236 | }; 237 | 238 | #endif // SEEEDOLED_H 239 | -------------------------------------------------------------------------------- /Grove - OLED Display 128x64/SeeedOLED.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SeeedOLED.cpp 3 | * A library for OLED Display 128*64 at RP 4 | * 5 | * Copyright (c) 2012 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : seeed fellow 8 | * Create Time: 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include "SeeedOLED.h" 44 | #include "font_8x8.h" 45 | #include "font_16x24.h" 46 | 47 | SeeedOLED::SeeedOLED(uint8_t deviceAddress) 48 | { 49 | _writeOpcode = deviceAddress & 0xFE; // low order bit = 0 for write 50 | _readOpcode = deviceAddress | 0x01; // low order bit = 1 for read 51 | 52 | initialize(); 53 | } 54 | 55 | SeeedOLED::~SeeedOLED() 56 | { 57 | //dtor 58 | } 59 | 60 | void SeeedOLED::initialize() 61 | { 62 | setHorizontalAddressingMode(); 63 | clearDisplay(); 64 | setInverted(false); 65 | setDisplayOn(); 66 | } 67 | 68 | void SeeedOLED::clearDisplay() 69 | { 70 | //setDisplayOff(); 71 | setPageAddress(0, MAX_PAGE); // all pages 72 | setColumnAddress(0, MAX_COL); // all columns 73 | for (uint8_t page = 0; page < PAGES; page++) { 74 | for (uint8_t col = 0; col < COLUMNS; col++) { 75 | _sendData(0x00); 76 | } 77 | } 78 | //setDisplayOn(); 79 | } 80 | 81 | void SeeedOLED::fillDisplay(uint8_t pattern, uint8_t start_page, uint8_t end_page, uint8_t start_col, uint8_t end_col) 82 | { 83 | int count = (end_page - start_page + 1) * (end_col - start_col + 1); 84 | 85 | //setDisplayOff(); 86 | setPageAddress(start_page, end_page); // set page window 87 | setColumnAddress(start_col, end_col); // set column window 88 | 89 | int file; 90 | char buf[1024] = {0}; 91 | 92 | if((file = open("/dev/i2c-1",O_RDWR)) < 0) { 93 | printf("Failed to open the bus."); 94 | } 95 | 96 | if(ioctl(file,I2C_SLAVE,_writeOpcode) < 0) { 97 | printf("Failed to acquire bus access and/or talk to slave.\n"); 98 | } 99 | buf[0] = 0x40; 100 | for (int i=1; i= 100) { 151 | scale_value = PRG_MAX_SCALE - 1 ; 152 | } else { 153 | scale_value = (percentage * PRG_MAX_SCALE) / 100; 154 | } 155 | 156 | //setDisplayOff(); 157 | setPageAddress(page, page); 158 | setColumnAddress(col, MAX_COL); 159 | 160 | // _i2c.start(); 161 | // _i2c.write(_writeOpcode); 162 | // _i2c.write(DATA_MODE); 163 | // 164 | // _i2c.write(PRG_LEFT_EDGE); // Write Data 165 | // 166 | for (uint8_t col = 0; col < scale_value; col++) { 167 | // _i2c.write(PRG_ACTIVE); // Write Data 168 | } 169 | // 170 | // _i2c.write(PRG_ACTIVE); // Write Data 171 | // 172 | for (uint8_t col = (scale_value+1); col < PRG_MAX_SCALE; col++) { 173 | // _i2c.write(PRG_NOT_ACTIVE); // Write Data 174 | } 175 | // 176 | // _i2c.write(PRG_RIGHT_EDGE); // Write Data 177 | // 178 | // _i2c.stop(); 179 | 180 | //setDisplayOn(); 181 | } 182 | 183 | void SeeedOLED::writeLevelBar(uint8_t page, uint8_t col, int percentage) 184 | { 185 | uint8_t scale_value; 186 | 187 | if (percentage <= 0) { 188 | scale_value = 0; 189 | } else if (percentage >= 100) { 190 | scale_value = PRG_MAX_SCALE - 1; 191 | } else { 192 | scale_value = (percentage * PRG_MAX_SCALE) / 100; 193 | } 194 | 195 | //setDisplayOff(); 196 | setPageAddress(page, page); 197 | setColumnAddress(col, MAX_COL); 198 | 199 | // _i2c.start(); 200 | // _i2c.write(_writeOpcode); 201 | // _i2c.write(DATA_MODE); 202 | // 203 | // _i2c.write(PRG_LEFT_EDGE); // Write Data 204 | // 205 | for (uint8_t col = 0; col < scale_value; col++) { 206 | // _i2c.write(PRG_NOT_ACTIVE); // Write Data 207 | } 208 | // 209 | // _i2c.write(PRG_ACTIVE); // Write Data at active meterlevel 210 | // 211 | for (uint8_t col = scale_value+1; col < PRG_MAX_SCALE; col++) { 212 | // _i2c.write(PRG_NOT_ACTIVE); // Write Data 213 | } 214 | // 215 | // _i2c.write(PRG_RIGHT_EDGE); // Write Data 216 | // 217 | // _i2c.stop(); 218 | 219 | //setDisplayOn(); 220 | } 221 | 222 | void SeeedOLED::setHorizontalAddressingMode() 223 | { 224 | setMemoryAddressingMode(HORIZONTAL_ADDRESSING_MODE); 225 | } 226 | 227 | void SeeedOLED::setVerticalAddressingMode() 228 | { 229 | setMemoryAddressingMode(VERTICAL_ADDRESSING_MODE); 230 | } 231 | 232 | void SeeedOLED::setPageAddressingMode() 233 | { 234 | setMemoryAddressingMode(PAGE_ADDRESSING_MODE); 235 | } 236 | 237 | void SeeedOLED::setMemoryAddressingMode(uint8_t mode) 238 | { 239 | _sendCommand(SET_MEMORY_ADDRESSING_MODE, mode); 240 | } 241 | 242 | void SeeedOLED::setPageAddress(uint8_t start, uint8_t end) 243 | { 244 | _sendCommand(SET_PAGE_ADDRESS, start, end); 245 | } 246 | 247 | void SeeedOLED::setColumnAddress(uint8_t start, uint8_t end) 248 | { 249 | _sendCommand(SET_COLUMN_ADDRESS, start, end); 250 | } 251 | 252 | void SeeedOLED::setDisplayStartLine(uint8_t line) 253 | { 254 | line = line & MAX_ROW; 255 | _sendCommand(SET_DISPLAY_START_LINE | line); 256 | } 257 | 258 | void SeeedOLED::setColumnStartForPageAddressingMode(uint8_t column) 259 | { 260 | column = column & MAX_COL; 261 | _sendCommand(SET_LOWER_COLUMN | ( column & 0x0F)); // lower nibble 262 | _sendCommand(SET_HIGHER_COLUMN | ((column>>4) & 0x0F)); // higher nibble 263 | } 264 | 265 | void SeeedOLED::setPageStartForPageAddressingMode(uint8_t page) 266 | { 267 | page = page & MAX_PAGE; 268 | _sendCommand(SET_PAGE_START_ADDRESS | page); 269 | } 270 | 271 | void SeeedOLED::setContrastControl(uint8_t contrast) 272 | { 273 | _sendCommand(SET_CONTRAST, contrast); 274 | } 275 | 276 | void SeeedOLED::setDisplayOn() 277 | { 278 | _sendCommand(SET_DISPLAY_POWER_ON); 279 | } 280 | 281 | void SeeedOLED::setDisplayOff() 282 | { 283 | _sendCommand(SET_DISPLAY_POWER_OFF); 284 | } 285 | 286 | void SeeedOLED::setDisplayPower(bool on) 287 | { 288 | if (on) { 289 | setDisplayOn(); 290 | } else { 291 | setDisplayOff(); 292 | } 293 | } 294 | 295 | void SeeedOLED::setDisplayNormal() 296 | { 297 | _sendCommand(SET_NORMAL_DISPLAY); 298 | } 299 | 300 | void SeeedOLED::setDisplayInverse() 301 | { 302 | _sendCommand(SET_INVERSE_DISPLAY); 303 | } 304 | 305 | void SeeedOLED::setDisplayBlink(bool on){ 306 | if (on) { 307 | _sendCommand(SET_FADE_BLINK, (BLINK_ENABLE | FADE_INTERVAL_128_FRAMES)); 308 | } 309 | else { 310 | _sendCommand(SET_FADE_BLINK, FADE_BLINK_DISABLE); 311 | } 312 | } 313 | 314 | void SeeedOLED::setDisplayFade(bool on) 315 | { 316 | if (on) { 317 | _sendCommand(SET_FADE_BLINK, (FADE_OUT_ENABLE | FADE_INTERVAL_128_FRAMES)); 318 | } 319 | else { 320 | _sendCommand(SET_FADE_BLINK, FADE_BLINK_DISABLE); 321 | } 322 | } 323 | 324 | void SeeedOLED::setDisplayFlip(bool left, bool down) { 325 | if (left) { 326 | // column address 0 is mapped to SEG0 (Reset) 327 | _sendCommand(SET_SEGMENT_REMAP_0); 328 | } 329 | else { 330 | // column address 127 is mapped to SEG0 331 | _sendCommand(SET_SEGMENT_REMAP_127); 332 | } 333 | 334 | if (down) { 335 | // Reset mode 336 | _sendCommand(SET_COMMON_REMAP_0); 337 | } 338 | else { 339 | // Flip Up/Down (Need to rewrite display before H effect shows) 340 | _sendCommand(SET_COMMON_REMAP_63); 341 | } 342 | 343 | } 344 | 345 | void SeeedOLED::setInternalIref() 346 | { 347 | // uint8_t cmds[2] = {SET_IREF_SELECTION, INTERNAL_IREF}; 348 | // _sendCommands(2, cmds); 349 | _sendCommand(SET_IREF_SELECTION, INTERNAL_IREF); 350 | } 351 | 352 | void SeeedOLED::setExternalIref() 353 | { 354 | // uint8_t cmds[2] = {SET_IREF_SELECTION, EXTERNAL_IREF}; 355 | // _sendCommands(2, cmds); 356 | _sendCommand(SET_IREF_SELECTION, EXTERNAL_IREF); 357 | } 358 | 359 | void SeeedOLED::setEntireDisplayOn() 360 | { 361 | _sendCommand(SET_ENTIRE_DISPLAY_ON); 362 | } 363 | 364 | void SeeedOLED::setEntireDisplayRAM() 365 | { 366 | _sendCommand(SET_DISPLAY_GDDRAM); 367 | } 368 | 369 | void SeeedOLED::setEntireDisplay(bool on) 370 | { 371 | if (on) { 372 | setEntireDisplayOn(); // All Pixels on 373 | } 374 | else { 375 | setEntireDisplayRAM(); // Pixels are RAM content 376 | } 377 | } 378 | 379 | void SeeedOLED::setContinuousHorizontalScroll(bool left, uint8_t start_page, uint8_t end_page, uint8_t interval) 380 | { 381 | if (left) { 382 | _sendCommand(SET_LEFT_HOR_SCROLL, 0x00, start_page, interval, end_page, 0x00, 0xFF); // Scroll Left 383 | } 384 | else { 385 | _sendCommand(SET_RIGHT_HOR_SCROLL, 0x00, start_page, interval, end_page, 0x00, 0xFF); // Scroll Right 386 | } 387 | } 388 | 389 | void SeeedOLED::setContinuousVerticalAndHorizontalScroll(bool left, uint8_t start_page, uint8_t end_page, uint8_t offset, uint8_t interval) 390 | { 391 | if (left) { 392 | _sendCommand(SET_VERT_LEFT_HOR_SCROLL, 0x00, start_page, interval, end_page, offset); // Scroll Left 393 | } 394 | else { 395 | _sendCommand(SET_VERT_RIGHT_HOR_SCROLL, 0x00, start_page, interval, end_page, offset); // Scroll Right 396 | } 397 | } 398 | 399 | void SeeedOLED::setVerticalScrollArea(uint8_t topRowsFixed, uint8_t scrollRows) 400 | { 401 | if((topRowsFixed + scrollRows) > ROWS) { 402 | scrollRows = ROWS - topRowsFixed; 403 | } 404 | _sendCommand(SET_VERTICAL_SCROLL_AREA, topRowsFixed, scrollRows); 405 | } 406 | 407 | void SeeedOLED::setDisplayScroll(bool on) 408 | { 409 | if (on) { 410 | _sendCommand(SET_ACTIVATE_SCROLL); // Scroll on 411 | } 412 | else { 413 | _sendCommand(SET_DEACTIVATE_SCROLL); // Scroll off 414 | } 415 | } 416 | 417 | void SeeedOLED::writeChar(char chr) 418 | { 419 | const uint8_t char_index = chr - 0x20; 420 | 421 | for(uint8_t i = 0; i < 8; i++) { 422 | if(_inverted) { 423 | _sendData( ~font_8x8[char_index][i] ); 424 | } else { 425 | _sendData( font_8x8[char_index][i] ); 426 | } 427 | } 428 | } 429 | 430 | void SeeedOLED::writeString(uint8_t row, uint8_t col, const char * txt) 431 | { 432 | uint16_t index = 0; 433 | uint16_t len = strlen(txt); 434 | 435 | setPageAddress(row, MAX_PAGE); 436 | const uint8_t col_addr = FONT8x8_WIDTH*col; 437 | setColumnAddress(col_addr, MAX_COL); 438 | 439 | while((col+index) < CHARS && (index < len)) { 440 | // write first line, starting at given position 441 | writeChar(txt[index++]); 442 | } 443 | 444 | // write remaining lines 445 | // write until the end of memory 446 | // then wrap around again from the top. 447 | if(index + 1 < len) { 448 | setPageAddress(row + 1, MAX_PAGE); 449 | setColumnAddress(0, MAX_COL); 450 | bool wrapEntireScreen = false; 451 | while(index + 1 < len) { 452 | writeChar(txt[index++]); 453 | // if we've written the last character space on the screen, 454 | // reset the page and column address so that it wraps around from the top again 455 | if(!wrapEntireScreen && (row*CHARS + col + index) > 127) { 456 | setPageAddress(0, MAX_PAGE); 457 | setColumnAddress(0, MAX_COL); 458 | wrapEntireScreen = true; 459 | } 460 | } 461 | } 462 | } 463 | 464 | void SeeedOLED::writeBigChar(uint8_t row, uint8_t col, char chr) 465 | { 466 | writeBitmap((uint8_t*) font_16x24[int(chr) - FONT16x24_START], row, (row + FONT16x24_BYTES - 1), col, (col + FONT16x24_WIDTH - 1)); 467 | } 468 | 469 | void SeeedOLED::_sendCommand(uint8_t command) 470 | { 471 | int file; 472 | char buf[2] = {0}; 473 | 474 | if((file = open("/dev/i2c-1",O_RDWR)) < 0) { 475 | printf("Failed to open the bus."); 476 | } 477 | 478 | if(ioctl(file,I2C_SLAVE,_writeOpcode) < 0) { 479 | printf("Failed to acquire bus access and/or talk to slave.\n"); 480 | } 481 | buf[0] = 0x80; 482 | buf[1] = command; 483 | write(file,buf,2); 484 | close(file); 485 | } 486 | 487 | void SeeedOLED::_sendCommand(uint8_t command, uint8_t param1) 488 | { 489 | int file; 490 | char buf[4] = {0}; 491 | 492 | if((file = open("/dev/i2c-1",O_RDWR)) < 0) { 493 | printf("Failed to open the bus."); 494 | } 495 | 496 | if(ioctl(file,I2C_SLAVE,_writeOpcode) < 0) { 497 | printf("Failed to acquire bus access and/or talk to slave.\n"); 498 | } 499 | buf[0] = 0x80; 500 | buf[1] = command; 501 | buf[2] = 0x80; 502 | buf[3] = param1; 503 | write(file,buf,4); 504 | close(file); 505 | } 506 | 507 | void SeeedOLED::_sendCommand(uint8_t command, uint8_t param1, uint8_t param2) 508 | { 509 | int file; 510 | char buf[6] = {0}; 511 | 512 | if((file = open("/dev/i2c-1",O_RDWR)) < 0) { 513 | printf("Failed to open the bus."); 514 | } 515 | 516 | if(ioctl(file,I2C_SLAVE,_writeOpcode) < 0) { 517 | printf("Failed to acquire bus access and/or talk to slave.\n"); 518 | } 519 | buf[0] = 0x80; 520 | buf[1] = command; 521 | buf[2] = 0x80; 522 | buf[3] = param1; 523 | buf[4] = 0x80; 524 | buf[5] = param2; 525 | write(file,buf,6); 526 | close(file); 527 | } 528 | 529 | void SeeedOLED::_sendCommand(uint8_t command, uint8_t param1, uint8_t param2, uint8_t param3, uint8_t param4, uint8_t param5) 530 | { 531 | int file; 532 | char buf[12] = {0}; 533 | 534 | if((file = open("/dev/i2c-1",O_RDWR)) < 0) { 535 | printf("Failed to open the bus."); 536 | } 537 | 538 | if(ioctl(file,I2C_SLAVE,_writeOpcode) < 0) { 539 | printf("Failed to acquire bus access and/or talk to slave.\n"); 540 | } 541 | buf[0] = 0x80; 542 | buf[1] = command; 543 | buf[2] = 0x80; 544 | buf[3] = param1; 545 | buf[4] = 0x80; 546 | buf[5] = param2; 547 | buf[6] = 0x80; 548 | buf[7] = param3; 549 | buf[8] = 0x80; 550 | buf[9] = param4; 551 | buf[10] = 0x80; 552 | buf[11] = param5; 553 | write(file,buf,12); 554 | close(file); 555 | } 556 | 557 | void SeeedOLED::_sendCommand(uint8_t command, uint8_t param1, uint8_t param2, uint8_t param3, uint8_t param4, uint8_t param5, uint8_t param6) 558 | { 559 | int file; 560 | char buf[14] = {0}; 561 | 562 | if((file = open("/dev/i2c-1",O_RDWR)) < 0) { 563 | printf("Failed to open the bus."); 564 | } 565 | 566 | if(ioctl(file,I2C_SLAVE,_writeOpcode) < 0) { 567 | printf("Failed to acquire bus access and/or talk to slave.\n"); 568 | } 569 | buf[0] = 0x80; 570 | buf[1] = command; 571 | buf[2] = 0x80; 572 | buf[3] = param1; 573 | buf[4] = 0x80; 574 | buf[5] = param2; 575 | buf[6] = 0x80; 576 | buf[7] = param3; 577 | buf[8] = 0x80; 578 | buf[9] = param4; 579 | buf[10] = 0x80; 580 | buf[11] = param5; 581 | buf[12] = 0x80; 582 | buf[13] = param6; 583 | write(file,buf,14); 584 | close(file); 585 | } 586 | 587 | void SeeedOLED::_sendData(uint8_t data) 588 | { 589 | int file; 590 | char buf[2] = {0}; 591 | 592 | if((file = open("/dev/i2c-1",O_RDWR)) < 0) { 593 | printf("Failed to open the bus."); 594 | } 595 | 596 | if(ioctl(file,I2C_SLAVE,_writeOpcode) < 0) { 597 | printf("Failed to acquire bus access and/or talk to slave.\n"); 598 | } 599 | buf[0] = 0x40; 600 | buf[1] = data; 601 | write(file,buf,2); 602 | close(file); 603 | } 604 | 605 | void SeeedOLED::_sendData(uint8_t len, uint8_t* data) 606 | { 607 | int file; 608 | char buf[64] = {0}; 609 | 610 | if((file = open("/dev/i2c-1",O_RDWR)) < 0) { 611 | printf("Failed to open the bus."); 612 | } 613 | 614 | if(ioctl(file,I2C_SLAVE,_writeOpcode) < 0) { 615 | printf("Failed to acquire bus access and/or talk to slave.\n"); 616 | } 617 | for(int i=0; i