├── .gitignore ├── .travis.yml ├── README.md ├── boards.txt ├── cores └── piduino │ ├── .gitignore │ ├── Arduino.h │ ├── Client.h │ ├── Console.cpp │ ├── Console.h │ ├── HardwareSerial.cpp │ ├── HardwareSerial.h │ ├── IPAddress.cpp │ ├── IPAddress.h │ ├── Print.cpp │ ├── Print.h │ ├── Printable.h │ ├── Server.h │ ├── Stream.cpp │ ├── Stream.h │ ├── StringArray.h │ ├── Udp.h │ ├── WCharacter.h │ ├── WMath.cpp │ ├── WProgram.h │ ├── WString.cpp │ ├── WString.h │ ├── bcm2835_registers.h │ ├── binary.h │ ├── cbuf.cpp │ ├── cbuf.h │ ├── idemonitor.c │ ├── idemonitor.h │ ├── pgmspace.h │ ├── piconsole.c │ ├── raspberry_pi_revision.c │ ├── raspberry_pi_revision.h │ ├── stdlib_noniso.cpp │ ├── stdlib_noniso.h │ ├── wiring.c │ ├── wiring_digital.c │ ├── wiring_ids.c │ ├── wiring_int.c │ ├── wiring_main.cpp │ ├── wiring_pulse.c │ ├── wiring_pwm.c │ ├── wiring_shift.c │ └── wiring_thread.c ├── doc ├── pi_monitor.png ├── pi_pass.png └── pi_select.png ├── libraries ├── Bridge │ ├── README.adoc │ ├── examples │ │ ├── Bridge │ │ │ └── Bridge.ino │ │ ├── ConsoleAsciiTable │ │ │ └── ConsoleAsciiTable.ino │ │ ├── ConsolePixel │ │ │ └── ConsolePixel.ino │ │ ├── ConsoleRead │ │ │ └── ConsoleRead.ino │ │ ├── Datalogger │ │ │ └── Datalogger.ino │ │ ├── FileWriteScript │ │ │ └── FileWriteScript.ino │ │ ├── HttpClient │ │ │ └── HttpClient.ino │ │ ├── Process │ │ │ └── Process.ino │ │ ├── ShellCommands │ │ │ └── ShellCommands.ino │ │ ├── TemperatureWebPanel │ │ │ ├── TemperatureWebPanel.ino │ │ │ └── www │ │ │ │ ├── index.html │ │ │ │ └── zepto.min.js │ │ ├── TimeCheck │ │ │ └── TimeCheck.ino │ │ └── YunSerialTerminal │ │ │ └── YunSerialTerminal.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── Bridge.cpp │ │ ├── Bridge.h │ │ ├── BridgeClient.cpp │ │ ├── BridgeClient.h │ │ ├── BridgeServer.cpp │ │ ├── BridgeServer.h │ │ ├── BridgeUdp.cpp │ │ ├── BridgeUdp.h │ │ ├── FileIO.cpp │ │ ├── FileIO.h │ │ ├── HttpClient.cpp │ │ ├── HttpClient.h │ │ ├── Mailbox.cpp │ │ ├── Mailbox.h │ │ ├── Process.cpp │ │ ├── Process.h │ │ ├── YunClient.h │ │ └── YunServer.h ├── DHT22 │ ├── DHT22.cpp │ ├── DHT22.h │ ├── DHT22.pdf │ ├── README │ ├── examples │ │ ├── DHTConsole │ │ │ └── DHTConsole.ino │ │ └── DHTSerial │ │ │ └── DHTSerial.ino │ └── keywords.txt ├── DS3231 │ ├── DS3231.cpp │ ├── DS3231.h │ └── keywords.txt ├── EEPROM │ ├── EEPROM.h │ ├── keywords.txt │ └── library.properties ├── Ethernet │ ├── README.adoc │ ├── examples │ │ ├── AdvancedChatServer │ │ │ └── AdvancedChatServer.ino │ │ ├── BarometricPressureWebServer │ │ │ └── BarometricPressureWebServer.ino │ │ ├── ChatServer │ │ │ └── ChatServer.ino │ │ ├── DhcpAddressPrinter │ │ │ └── DhcpAddressPrinter.ino │ │ ├── DhcpChatServer │ │ │ └── DhcpChatServer.ino │ │ ├── TelnetClient │ │ │ └── TelnetClient.ino │ │ ├── UDPSendReceiveString │ │ │ └── UDPSendReceiveString.ino │ │ ├── UdpNtpClient │ │ │ └── UdpNtpClient.ino │ │ ├── WebClient │ │ │ └── WebClient.ino │ │ ├── WebClientRepeating │ │ │ └── WebClientRepeating.ino │ │ └── WebServer │ │ │ └── WebServer.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── Dhcp.cpp │ │ ├── Dhcp.h │ │ ├── Dns.cpp │ │ ├── Dns.h │ │ ├── Ethernet.cpp │ │ ├── Ethernet.h │ │ ├── EthernetClient.cpp │ │ ├── EthernetClient.h │ │ ├── EthernetServer.cpp │ │ ├── EthernetServer.h │ │ ├── EthernetUdp.cpp │ │ ├── EthernetUdp.h │ │ └── utility │ │ ├── socket.cpp │ │ ├── socket.h │ │ ├── util.h │ │ ├── w5100.cpp │ │ └── w5100.h ├── NOKIA_LCD │ ├── NOKIA_LCD.cpp │ └── NOKIA_LCD.h ├── SD │ ├── README.adoc │ ├── examples │ │ ├── CardInfo │ │ │ └── CardInfo.ino │ │ ├── Datalogger │ │ │ └── Datalogger.ino │ │ ├── DumpFile │ │ │ └── DumpFile.ino │ │ ├── Files │ │ │ └── Files.ino │ │ ├── ReadWrite │ │ │ └── ReadWrite.ino │ │ └── listfiles │ │ │ └── listfiles.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── File.cpp │ │ ├── README.txt │ │ ├── SD.cpp │ │ ├── SD.h │ │ └── utility │ │ ├── FatStructs.h │ │ ├── Sd2Card.cpp │ │ ├── Sd2Card.h │ │ ├── Sd2PinMap.h │ │ ├── SdFat.h │ │ ├── SdFatUtil.h │ │ ├── SdFatmainpage.h │ │ ├── SdFile.cpp │ │ ├── SdInfo.h │ │ └── SdVolume.cpp ├── SPI │ ├── SPI.cpp │ ├── SPI.h │ ├── examples │ │ ├── BarometricPressureSensor │ │ │ └── BarometricPressureSensor.ino │ │ └── DigitalPotControl │ │ │ └── DigitalPotControl.ino │ ├── keywords.txt │ └── library.properties ├── TTY │ ├── TTY.cpp │ ├── TTY.h │ ├── keywords.txt │ └── library.properties └── Wire │ ├── Wire.cpp │ ├── Wire.h │ ├── examples │ ├── SFRRanger_reader │ │ └── SFRRanger_reader.ino │ └── digital_potentiometer │ │ └── digital_potentiometer.ino │ ├── keywords.txt │ ├── library.properties │ └── utility │ ├── twi.c │ └── twi.h ├── platform.txt ├── programmers.txt ├── tools ├── .gitignore ├── Makefile ├── arduino.service ├── arpi_bins │ ├── merge-sketch-with-bootloader.lua │ ├── run-avrdude │ ├── run-sketch │ └── telnet ├── compat │ └── include │ │ └── avr │ │ └── pgmspace.h └── upload.sh ├── travis └── run-examples.sh └── variants └── bplus └── pins_arduino.h /.gitignore: -------------------------------------------------------------------------------- 1 | tools/arm-none-linux-gnueabi 2 | tools/arm-none-linux-gnueabi-old 3 | tools/arm-linux-gnueabihf 4 | /.project 5 | .DS_Store 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: bash 3 | os: 4 | - linux 5 | 6 | git: 7 | depth: false 8 | 9 | stages: 10 | - build 11 | 12 | jobs: 13 | include: 14 | 15 | - name: "Build Arduino 0" 16 | if: tag IS blank AND (type = pull_request OR (type = push AND branch = master)) 17 | stage: build 18 | script: $TRAVIS_BUILD_DIR/travis/run-examples.sh 0 5 19 | 20 | - name: "Build Arduino 1" 21 | if: tag IS blank AND (type = pull_request OR (type = push AND branch = master)) 22 | stage: build 23 | script: $TRAVIS_BUILD_DIR/travis/run-examples.sh 1 5 24 | 25 | - name: "Build Arduino 2" 26 | if: tag IS blank AND (type = pull_request OR (type = push AND branch = master)) 27 | stage: build 28 | script: $TRAVIS_BUILD_DIR/travis/run-examples.sh 2 5 29 | 30 | - name: "Build Arduino 3" 31 | if: tag IS blank AND (type = pull_request OR (type = push AND branch = master)) 32 | stage: build 33 | script: $TRAVIS_BUILD_DIR/travis/run-examples.sh 3 5 34 | 35 | - name: "Build Arduino 4" 36 | if: tag IS blank AND (type = pull_request OR (type = push AND branch = master)) 37 | stage: build 38 | script: $TRAVIS_BUILD_DIR/travis/run-examples.sh 4 5 39 | 40 | notifications: 41 | email: 42 | on_success: change 43 | on_failure: change 44 | webhooks: 45 | urls: 46 | - https://webhooks.gitter.im/e/46eabf7ad1d622bcd8cc 47 | on_success: change # options: [always|never|change] default: always 48 | on_failure: always # options: [always|never|change] default: always 49 | on_start: false # default: false 50 | -------------------------------------------------------------------------------- /boards.txt: -------------------------------------------------------------------------------- 1 | menu.SerialDestination=Serial to Console 2 | menu.GDBDebug=Enable gdb 3 | 4 | ############################################################## 5 | bplus.name=RaspberryPI B+/2 6 | bplus.upload.via_ssh=true 7 | 8 | bplus.upload.tool=scp 9 | bplus.upload.verbose= 10 | bplus.upload.speed=115200 11 | 12 | bplus.build.mcu=bplus 13 | bplus.build.core=piduino 14 | bplus.build.variant=bplus 15 | bplus.build.board=RASPI 16 | 17 | bplus.build.f_cpu=700000000L 18 | bplus.build.debug_flags= 19 | bplus.build.optimization_flags=-O3 20 | bplus.build.extra_flags=-DRASPIå 21 | 22 | ############################################################## 23 | bplus.menu.SerialDestination.disabled=Disabled 24 | bplus.menu.SerialDestination.disabled.build.extra_flags=-DRASPI 25 | bplus.menu.SerialDestination.enabled=Enabled 26 | bplus.menu.SerialDestination.enabled.build.extra_flags=-DRASPI -DSERIAL_TO_CONSOLE 27 | 28 | ############################################################## 29 | # Add a menu entry called "Enable gdb" which is used to enable or disable support for the 30 | # GNU Debugger called "gdb". Dependening on the settings that that user selects, we either 31 | # compile with or without the "-g" flag. Adding the "-g" flag includes symbolic debugging. 32 | # The symbol "build.debug_flags" get set based on the value the user selects. 33 | # 34 | bplus.menu.GDBDebug.disabled=Disabled 35 | bplus.menu.GDBDebug.disabled.build.debug_flags= 36 | bplus.menu.GDBDebug.disabled.build.optimization_flags=-O3 37 | bplus.menu.GDBDebug.enabled=Enabled 38 | bplus.menu.GDBDebug.enabled.build.debug_flags=-g 39 | bplus.menu.GDBDebug.enabled.build.optimization_flags= -------------------------------------------------------------------------------- /cores/piduino/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | -------------------------------------------------------------------------------- /cores/piduino/Client.h: -------------------------------------------------------------------------------- 1 | /* 2 | Client.h - Base class that provides Client 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef client_h 21 | #define client_h 22 | #include "Print.h" 23 | #include "Stream.h" 24 | #include "IPAddress.h" 25 | 26 | class Client : public Stream { 27 | 28 | public: 29 | virtual int connect(IPAddress ip, uint16_t port) =0; 30 | virtual int connect(const char *host, uint16_t port) =0; 31 | virtual size_t write(uint8_t) =0; 32 | virtual size_t write(const uint8_t *buf, size_t size) =0; 33 | virtual int available() = 0; 34 | virtual int read() = 0; 35 | virtual int read(uint8_t *buf, size_t size) = 0; 36 | virtual int peek() = 0; 37 | virtual void flush() = 0; 38 | virtual void stop() = 0; 39 | virtual uint8_t connected() = 0; 40 | virtual operator bool() = 0; 41 | protected: 42 | uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /cores/piduino/Console.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | LinuxConsole.cpp - Linux STDIN/STDOUT library for Wiring 3 | Copyright (c) 2015 Hristo Gochkov. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "Arduino.h" 25 | 26 | #include "Console.h" 27 | #include "idemonitor.h" 28 | 29 | void LinuxConsole::begin(){ 30 | console_begin(); 31 | } 32 | 33 | void LinuxConsole::end(){ 34 | console_end(); 35 | } 36 | 37 | int LinuxConsole::available(void){ 38 | return idemonitor_available() + console_available(); 39 | } 40 | 41 | int LinuxConsole::peek(void){ 42 | if(idemonitor_connected() && idemonitor_available()) 43 | return idemonitor_peek(); 44 | return console_peek(); 45 | } 46 | 47 | int LinuxConsole::read(void){ 48 | if(idemonitor_connected() && idemonitor_available()) 49 | return idemonitor_read_char(); 50 | return console_read(); 51 | } 52 | 53 | void LinuxConsole::flush(){ 54 | idemonitor_flush(); 55 | console_flush(); 56 | } 57 | 58 | size_t LinuxConsole::write(uint8_t c){ 59 | if(idemonitor_connected()) 60 | idemonitor_write((char*)&c, 1); 61 | console_write(c); 62 | return 1; 63 | } 64 | 65 | LinuxConsole Console; 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /cores/piduino/Console.h: -------------------------------------------------------------------------------- 1 | /* 2 | LinuxConsole.h - Linux STDIN/STDOUT library for Wiring 3 | Copyright (c) 2015 Hristo Gochkov. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef LINUX_CONSOLE_H 21 | #define LINUX_CONSOLE_H 22 | 23 | #include 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | void console_begin(void); 31 | void console_end(void); 32 | void console_run(void); 33 | void console_attach_signal_handlers(void); 34 | void console_signal_handler(int); 35 | 36 | void console_echo(void); 37 | void console_noecho(void); 38 | void console_mode_raw(void); 39 | void console_mode_line(void); 40 | 41 | int console_rx_empty(void); 42 | 43 | size_t console_tx(uint8_t data); 44 | uint8_t console_rx(void); 45 | 46 | uint8_t console_read(void); 47 | uint8_t console_peek(void); 48 | void console_flush(void); 49 | void console_write(uint8_t str); 50 | int console_available(void); 51 | 52 | #ifdef __cplusplus 53 | } 54 | 55 | #include "Stream.h" 56 | class BridgeClass; 57 | 58 | class LinuxConsole : public Stream{ 59 | protected: 60 | 61 | public: 62 | LinuxConsole(BridgeClass &_b __attribute__((unused))){} 63 | void buffer(uint8_t size __attribute__((unused))){} 64 | void noBuffer(){} 65 | bool connected(){return true;} 66 | 67 | inline LinuxConsole(){} 68 | void begin(); 69 | inline void begin(uint32_t baud __attribute__((unused))){} 70 | void end(); 71 | virtual int available(void); 72 | virtual int peek(void); 73 | virtual int read(void); 74 | virtual void flush(void); 75 | virtual size_t write(uint8_t); 76 | inline size_t write(unsigned long n) { return write((uint8_t)n); } 77 | inline size_t write(long n) { return write((uint8_t)n); } 78 | inline size_t write(unsigned int n) { return write((uint8_t)n); } 79 | inline size_t write(int n) { return write((uint8_t)n); } 80 | using Print::write; // pull in write(str) and write(buf, size) from Print 81 | operator bool() { return true; } 82 | }; 83 | 84 | extern LinuxConsole Console; 85 | #endif 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /cores/piduino/HardwareSerial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.cpp - Hardware serial library for Wiring 3 | Copyright (c) 2015 Hristo Gochkov. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "Arduino.h" 25 | 26 | #include "HardwareSerial.h" 27 | #include "cbuf.h" 28 | 29 | 30 | #define UART_BUFFER_SIZE 1024 31 | 32 | static cbuf _rx_buffer(1024); 33 | static volatile bool _uart_check_run = false; 34 | 35 | //called by the interrupt check thread 36 | void uart_check_fifos(){ 37 | if(!_uart_check_run) return; 38 | while((UART0FR & (1 << UART0RXFE)) == 0) 39 | _rx_buffer.write(UART0DR); 40 | } 41 | 42 | size_t HardwareSerial::write(uint8_t c){ 43 | while(UART0FR & _BV(UART0TXFF)); 44 | UART0DR = c; 45 | return 1; 46 | } 47 | 48 | void HardwareSerial::begin(uint32_t baud){ 49 | uint32_t divider = 12000000/baud; 50 | pinMode(14, GPF0); // TXD 51 | pinMode(15, GPF0); // RXD 52 | UART0IBRD = divider >> 6; 53 | UART0FBRD = divider & 0x3F; 54 | UART0LCRH = (UART0WLEN_8BIT << UART0WLEN) | _BV(UART0FEN); 55 | UART0CR = _BV(UART0EN) | _BV(UART0TXE) | _BV(UART0RXE); 56 | _uart_check_run = true; 57 | } 58 | 59 | void HardwareSerial::end(){ 60 | _uart_check_run = false; 61 | UART0LCRH = 0; 62 | UART0CR = 0; 63 | pinMode(14, GPFI); // TXD 64 | pinMode(15, GPFI); // RXD 65 | } 66 | 67 | int HardwareSerial::available(void){ 68 | return _rx_buffer.getSize(); 69 | } 70 | 71 | int HardwareSerial::peek(void){ 72 | return _rx_buffer.peek(); 73 | } 74 | 75 | int HardwareSerial::read(void){ 76 | return _rx_buffer.read(); 77 | } 78 | 79 | void HardwareSerial::flush(){ 80 | _rx_buffer.flush(); 81 | } 82 | 83 | #ifdef SERIAL_TO_CONSOLE 84 | HardwareSerial Serial1; 85 | #else 86 | HardwareSerial Serial; 87 | #endif 88 | 89 | 90 | -------------------------------------------------------------------------------- /cores/piduino/HardwareSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.h - Hardware serial library for Wiring 3 | Copyright (c) 2015 Hristo Gochkov. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef HardwareSerial_h 21 | #define HardwareSerial_h 22 | 23 | #include "Stream.h" 24 | 25 | class HardwareSerial : public Stream { 26 | protected: 27 | 28 | public: 29 | inline HardwareSerial(){} 30 | void begin(uint32_t baud); 31 | void end(); 32 | virtual int available(void); 33 | virtual int peek(void); 34 | virtual int read(void); 35 | virtual void flush(void); 36 | virtual size_t write(uint8_t); 37 | inline size_t write(unsigned long n) { return write((uint8_t)n); } 38 | inline size_t write(long n) { return write((uint8_t)n); } 39 | inline size_t write(unsigned int n) { return write((uint8_t)n); } 40 | inline size_t write(int n) { return write((uint8_t)n); } 41 | using Print::write; // pull in write(str) and write(buf, size) from Print 42 | operator bool() { return true; } 43 | }; 44 | 45 | #ifdef SERIAL_TO_CONSOLE 46 | extern HardwareSerial Serial1; 47 | #define Serial Console 48 | #else 49 | extern HardwareSerial Serial; 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /cores/piduino/IPAddress.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | IPAddress.cpp - Base class that provides IPAddress 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | IPAddress::IPAddress() 24 | { 25 | _address.dword = 0; 26 | } 27 | 28 | IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) 29 | { 30 | _address.bytes[0] = first_octet; 31 | _address.bytes[1] = second_octet; 32 | _address.bytes[2] = third_octet; 33 | _address.bytes[3] = fourth_octet; 34 | } 35 | 36 | IPAddress::IPAddress(uint32_t address) 37 | { 38 | _address.dword = address; 39 | } 40 | 41 | IPAddress::IPAddress(const uint8_t *address) 42 | { 43 | memcpy(_address.bytes, address, sizeof(_address.bytes)); 44 | } 45 | 46 | bool IPAddress::fromString(const char *address) 47 | { 48 | // TODO: add support for "a", "a.b", "a.b.c" formats 49 | 50 | uint16_t acc = 0; // Accumulator 51 | uint8_t dots = 0; 52 | 53 | while (*address) 54 | { 55 | char c = *address++; 56 | if (c >= '0' && c <= '9') 57 | { 58 | acc = acc * 10 + (c - '0'); 59 | if (acc > 255) { 60 | // Value out of [0..255] range 61 | return false; 62 | } 63 | } 64 | else if (c == '.') 65 | { 66 | if (dots == 3) { 67 | // Too much dots (there must be 3 dots) 68 | return false; 69 | } 70 | _address.bytes[dots++] = acc; 71 | acc = 0; 72 | } 73 | else 74 | { 75 | // Invalid char 76 | return false; 77 | } 78 | } 79 | 80 | if (dots != 3) { 81 | // Too few dots (there must be 3 dots) 82 | return false; 83 | } 84 | _address.bytes[3] = acc; 85 | return true; 86 | } 87 | 88 | IPAddress& IPAddress::operator=(const uint8_t *address) 89 | { 90 | memcpy(_address.bytes, address, sizeof(_address.bytes)); 91 | return *this; 92 | } 93 | 94 | IPAddress& IPAddress::operator=(uint32_t address) 95 | { 96 | _address.dword = address; 97 | return *this; 98 | } 99 | 100 | bool IPAddress::operator==(const uint8_t* addr) const 101 | { 102 | return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0; 103 | } 104 | 105 | size_t IPAddress::printTo(Print& p) const 106 | { 107 | size_t n = 0; 108 | for (int i =0; i < 3; i++) 109 | { 110 | n += p.print(_address.bytes[i], DEC); 111 | n += p.print('.'); 112 | } 113 | n += p.print(_address.bytes[3], DEC); 114 | return n; 115 | } 116 | 117 | -------------------------------------------------------------------------------- /cores/piduino/IPAddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | IPAddress.h - Base class that provides IPAddress 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef IPAddress_h 21 | #define IPAddress_h 22 | 23 | #include 24 | #include "Printable.h" 25 | #include "WString.h" 26 | 27 | // A class to make it easier to handle and pass around IP addresses 28 | 29 | class IPAddress : public Printable { 30 | private: 31 | union { 32 | uint8_t bytes[4]; // IPv4 address 33 | uint32_t dword; 34 | } _address; 35 | 36 | // Access the raw byte array containing the address. Because this returns a pointer 37 | // to the internal structure rather than a copy of the address this function should only 38 | // be used when you know that the usage of the returned uint8_t* will be transient and not 39 | // stored. 40 | uint8_t* raw_address() { return _address.bytes; }; 41 | 42 | public: 43 | // Constructors 44 | IPAddress(); 45 | virtual ~IPAddress(){} 46 | IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); 47 | IPAddress(uint32_t address); 48 | IPAddress(const uint8_t *address); 49 | 50 | bool fromString(const char *address); 51 | bool fromString(const String &address) { return fromString(address.c_str()); } 52 | 53 | // Overloaded cast operator to allow IPAddress objects to be used where a pointer 54 | // to a four-byte uint8_t array is expected 55 | operator uint32_t() const { return _address.dword; }; 56 | bool operator==(const IPAddress& addr) const { return _address.dword == addr._address.dword; }; 57 | bool operator==(const uint8_t* addr) const; 58 | 59 | // Overloaded index operator to allow getting and setting individual octets of the address 60 | uint8_t operator[](int index) const { return _address.bytes[index]; }; 61 | uint8_t& operator[](int index) { return _address.bytes[index]; }; 62 | 63 | // Overloaded copy operators to allow initialisation of IPAddress objects from other types 64 | IPAddress& operator=(const uint8_t *address); 65 | IPAddress& operator=(uint32_t address); 66 | 67 | virtual size_t printTo(Print& p) const; 68 | 69 | friend class EthernetClass; 70 | friend class UDP; 71 | friend class Client; 72 | friend class Server; 73 | friend class DhcpClass; 74 | friend class DNSClient; 75 | }; 76 | 77 | const IPAddress INADDR4_NONE(0,0,0,0); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /cores/piduino/Print.h: -------------------------------------------------------------------------------- 1 | /* 2 | Print.h - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Print_h 21 | #define Print_h 22 | 23 | #include 24 | #include // for size_t 25 | 26 | #include "WString.h" 27 | #include "Printable.h" 28 | 29 | #define DEC 10 30 | #define HEX 16 31 | #define OCT 8 32 | #define BIN 2 33 | 34 | class Print{ 35 | private: 36 | int write_error; 37 | size_t printNumber(unsigned long, uint8_t); 38 | size_t printFloat(double, uint8_t); 39 | protected: 40 | void setWriteError(int err = 1) { write_error = err; } 41 | public: 42 | Print(): write_error(0) {} 43 | virtual ~Print(){} 44 | 45 | int getWriteError() { return write_error; } 46 | void clearWriteError() { setWriteError(0); } 47 | 48 | virtual size_t write(uint8_t){ return 0; } 49 | virtual size_t write(const uint8_t *buffer, size_t size); 50 | size_t write(const char *buffer, size_t size) { return write((const uint8_t *)buffer, size); } 51 | size_t write(const char *str){ 52 | if (str == NULL) return 0; 53 | return write((const uint8_t *)str, strlen(str)); 54 | } 55 | 56 | size_t printf(const char *format, ...); 57 | size_t print(const String &); 58 | size_t print(const char*); 59 | size_t print(char); 60 | size_t print(unsigned char, int = DEC); 61 | size_t print(int, int = DEC); 62 | size_t print(unsigned int, int = DEC); 63 | size_t print(long, int = DEC); 64 | size_t print(unsigned long, int = DEC); 65 | size_t print(double, int = 2); 66 | size_t print(const Printable&); 67 | 68 | size_t println(const String &s); 69 | size_t println(const char*); 70 | size_t println(char); 71 | size_t println(unsigned char, int = DEC); 72 | size_t println(int, int = DEC); 73 | size_t println(unsigned int, int = DEC); 74 | size_t println(long, int = DEC); 75 | size_t println(unsigned long, int = DEC); 76 | size_t println(double, int = 2); 77 | size_t println(const Printable&); 78 | virtual size_t println(void); 79 | }; 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /cores/piduino/Printable.h: -------------------------------------------------------------------------------- 1 | /* 2 | Printable.h - Interface class that allows printing of complex types 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Printable_h 21 | #define Printable_h 22 | 23 | #include 24 | 25 | class Print; 26 | 27 | /** The Printable class provides a way for new classes to allow themselves to be printed. 28 | By deriving from Printable and implementing the printTo method, it will then be possible 29 | for users to print out instances of this class by passing them into the usual 30 | Print::print and Print::println methods. 31 | */ 32 | 33 | class Printable 34 | { 35 | public: 36 | virtual size_t printTo(Print& p) const = 0; 37 | }; 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /cores/piduino/Server.h: -------------------------------------------------------------------------------- 1 | /* 2 | Server.h - Base class that provides Server 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef server_h 21 | #define server_h 22 | 23 | #include "Print.h" 24 | 25 | class Server : public Print { 26 | public: 27 | virtual void begin() =0; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /cores/piduino/StringArray.h: -------------------------------------------------------------------------------- 1 | /* 2 | * StringArray.h 3 | * 4 | * Created on: 18.12.2015 г. 5 | * Author: ficeto 6 | */ 7 | 8 | #ifndef STRINGARRAY_H_ 9 | #define STRINGARRAY_H_ 10 | 11 | #include "stddef.h" 12 | #include "WString.h" 13 | 14 | class StringArrayItem; 15 | class StringArrayItem { 16 | private: 17 | String _string; 18 | public: 19 | StringArrayItem *next; 20 | StringArrayItem(String str):_string(str), next(NULL){} 21 | ~StringArrayItem(){} 22 | String string(){ return _string; } 23 | }; 24 | 25 | class StringArray { 26 | private: 27 | StringArrayItem *_items; 28 | public: 29 | StringArray():_items(NULL){} 30 | StringArray(StringArrayItem *items):_items(items){} 31 | ~StringArray(){} 32 | StringArrayItem *items(){ 33 | return _items; 34 | } 35 | void add(String str){ 36 | StringArrayItem *it = new StringArrayItem(str); 37 | if(_items == NULL){ 38 | _items = it; 39 | } else { 40 | StringArrayItem *i = _items; 41 | while(i->next != NULL) i = i->next; 42 | i->next = it; 43 | } 44 | } 45 | size_t length(){ 46 | size_t i = 0; 47 | StringArrayItem *it = _items; 48 | while(it != NULL){ 49 | i++; 50 | it = it->next; 51 | } 52 | return i; 53 | } 54 | bool contains(String str){ 55 | StringArrayItem *it = _items; 56 | while(it != NULL){ 57 | if(it->string() == str) 58 | return true; 59 | it = it->next; 60 | } 61 | return false; 62 | } 63 | String get(size_t index){ 64 | size_t i = 0; 65 | StringArrayItem *it = _items; 66 | while(it != NULL){ 67 | if(i++ == index) 68 | return it->string(); 69 | it = it->next; 70 | } 71 | return String(); 72 | } 73 | bool remove(size_t index){ 74 | StringArrayItem *it = _items; 75 | if(!index){ 76 | if(_items == NULL) 77 | return false; 78 | _items = _items->next; 79 | delete it; 80 | return true; 81 | } 82 | size_t i = 0; 83 | StringArrayItem *pit = _items; 84 | while(it != NULL){ 85 | if(i++ == index){ 86 | pit->next = it->next; 87 | delete it; 88 | return true; 89 | } 90 | pit = it; 91 | it = it->next; 92 | } 93 | return false; 94 | } 95 | bool remove(String str){ 96 | StringArrayItem *it = _items; 97 | StringArrayItem *pit = _items; 98 | while(it != NULL){ 99 | if(it->string() == str){ 100 | if(it == _items){ 101 | _items = _items->next; 102 | } else { 103 | pit->next = it->next; 104 | } 105 | delete it; 106 | return true; 107 | } 108 | pit = it; 109 | it = it->next; 110 | } 111 | return false; 112 | } 113 | void free(){ 114 | StringArrayItem *it; 115 | while(_items != NULL){ 116 | it = _items; 117 | _items = _items->next; 118 | delete it; 119 | } 120 | } 121 | }; 122 | 123 | 124 | 125 | #endif /* STRINGARRAY_H_ */ 126 | -------------------------------------------------------------------------------- /cores/piduino/WMath.cpp: -------------------------------------------------------------------------------- 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Wiring project - http://wiring.org.co 5 | Copyright (c) 2004-06 Hernando Barragan 6 | Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/ 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | */ 23 | 24 | extern "C" { 25 | #include "stdlib.h" 26 | } 27 | 28 | long map(long x, long in_min, long in_max, long out_min, long out_max){ 29 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 30 | } 31 | 32 | unsigned int makeWord(unsigned int w) { return w; } 33 | unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } 34 | 35 | void randomSeed(unsigned long seed) 36 | { 37 | if (seed != 0) { 38 | srandom(seed); 39 | } 40 | } 41 | 42 | long random(long howbig) 43 | { 44 | if (howbig == 0) { 45 | return 0; 46 | } 47 | return random() % howbig; 48 | } 49 | 50 | long random(long howsmall, long howbig) 51 | { 52 | if (howsmall >= howbig) { 53 | return howsmall; 54 | } 55 | long diff = howbig - howsmall; 56 | return random(diff) + howsmall; 57 | } 58 | -------------------------------------------------------------------------------- /cores/piduino/WProgram.h: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | -------------------------------------------------------------------------------- /cores/piduino/cbuf.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | cbuf.cpp - Circular buffer implementation 3 | Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 4 | This file is part of the esp8266 core for Arduino environment. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "cbuf.h" 22 | #include "Arduino.h" 23 | 24 | cbuf::cbuf(size_t size) : 25 | _size(size), _buf(new char[size]), _bufend(_buf + size), _begin(_buf), _end(_begin) { 26 | } 27 | 28 | cbuf::~cbuf() { 29 | delete[] _buf; 30 | } 31 | 32 | size_t cbuf::getSize() const { 33 | if(_end >= _begin) { 34 | return _end - _begin; 35 | } 36 | return _size - (_begin - _end); 37 | } 38 | 39 | size_t cbuf::room() const { 40 | if(_end >= _begin) { 41 | return _size - (_end - _begin) - 1; 42 | } 43 | return _begin - _end - 1; 44 | } 45 | 46 | bool cbuf::empty() const { 47 | return _begin == _end; 48 | } 49 | 50 | bool cbuf::full() const { 51 | return wrap_if_bufend(_end + 1) == _begin; 52 | } 53 | 54 | int cbuf::peek() { 55 | if(empty()) return -1; 56 | 57 | return static_cast(*_begin); 58 | } 59 | 60 | size_t cbuf::read(char* dst, size_t size) { 61 | size_t bytes_available = getSize(); 62 | size_t size_to_read = (size < bytes_available) ? size : bytes_available; 63 | size_t size_read = size_to_read; 64 | if(_end < _begin && size_to_read > (size_t)(_bufend - _begin)) { 65 | size_t top_size = _bufend - _begin; 66 | memcpy(dst, _begin, top_size); 67 | _begin = _buf; 68 | size_to_read -= top_size; 69 | dst += top_size; 70 | } 71 | memcpy(dst, _begin, size_to_read); 72 | _begin = wrap_if_bufend(_begin + size_to_read); 73 | return size_read; 74 | } 75 | 76 | int cbuf::read() { 77 | if(empty()) return -1; 78 | 79 | char result = *_begin; 80 | _begin = wrap_if_bufend(_begin + 1); 81 | return static_cast(result); 82 | } 83 | 84 | size_t cbuf::write(const char* src, size_t size) { 85 | size_t bytes_available = room(); 86 | size_t size_to_write = (size < bytes_available) ? size : bytes_available; 87 | size_t size_written = size_to_write; 88 | if(_end >= _begin && size_to_write > (size_t)(_bufend - _end)) { 89 | size_t top_size = _bufend - _end; 90 | memcpy(_end, src, top_size); 91 | _end = _buf; 92 | size_to_write -= top_size; 93 | src += top_size; 94 | } 95 | memcpy(_end, src, size_to_write); 96 | _end = wrap_if_bufend(_end + size_to_write); 97 | return size_written; 98 | } 99 | 100 | size_t cbuf::write(char c) { 101 | if(full()) return 0; 102 | 103 | *_end = c; 104 | _end = wrap_if_bufend(_end + 1); 105 | return 1; 106 | } 107 | 108 | void cbuf::flush() { 109 | _begin = _buf; 110 | _end = _buf; 111 | } 112 | 113 | char* cbuf::wrap_if_bufend(char* ptr) const { 114 | return (ptr == _bufend) ? _buf : ptr; 115 | } 116 | -------------------------------------------------------------------------------- /cores/piduino/cbuf.h: -------------------------------------------------------------------------------- 1 | /* 2 | cbuf.h - Circular buffer implementation 3 | Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 4 | This file is part of the esp8266 core for Arduino environment. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef __cbuf_h 22 | #define __cbuf_h 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | class cbuf { 29 | public: 30 | cbuf(size_t size); 31 | ~cbuf(); 32 | size_t getSize() const; 33 | size_t room() const ; 34 | bool empty() const ; 35 | bool full() const ; 36 | int peek() ; 37 | int read(); 38 | size_t read(char* dst, size_t size); 39 | size_t write(char c); 40 | size_t write(const char* src, size_t size); 41 | void flush(); 42 | 43 | private: 44 | const size_t _size; 45 | char* _buf; 46 | const char* const _bufend; 47 | char* _begin; 48 | char* _end; 49 | 50 | char* wrap_if_bufend(char* ptr) const ; 51 | }; 52 | 53 | #endif//__cbuf_h 54 | -------------------------------------------------------------------------------- /cores/piduino/idemonitor.h: -------------------------------------------------------------------------------- 1 | /* 2 | idemonitor.h - Ardiono IDE remote monitor implementation for Raspberry Pi 3 | Copyright (c) 2015 Hristo Gochkov. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef _IDE_MONITOR_H 21 | #define _IDE_MONITOR_H 22 | 23 | #include 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | void idemonitor_begin(void); 31 | void idemonitor_run(void); 32 | uint8_t idemonitor_connected(); 33 | int idemonitor_write(char * data, size_t len); 34 | size_t idemonitor_available(); 35 | size_t idemonitor_read(char *buf, size_t len); 36 | int idemonitor_read_char(); 37 | int idemonitor_peek(); 38 | void idemonitor_flush(); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /cores/piduino/pgmspace.h: -------------------------------------------------------------------------------- 1 | #ifndef PGMSPACE_INCLUDE 2 | #define PGMSPACE_INCLUDE 3 | 4 | typedef char __FlashStringHelper; 5 | #define PROGMEM 6 | #define PSTR(s) (s) 7 | #define F(string_literal) (reinterpret_cast(PSTR(string_literal))) 8 | 9 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) 10 | #define pgm_read_word(addr) (*(const unsigned short *)(addr)) 11 | #define pgm_read_dword(addr) (*(const unsigned long *)(addr)) 12 | #define pgm_read_float(addr) (*(const float *)(addr)) 13 | 14 | #define pgm_read_byte_near(addr) pgm_read_byte(addr) 15 | #define pgm_read_word_near(addr) pgm_read_word(addr) 16 | #define pgm_read_dword_near(addr) pgm_read_dword(addr) 17 | #define pgm_read_float_near(addr) pgm_read_float(addr) 18 | #define pgm_read_byte_far(addr) pgm_read_byte(addr) 19 | #define pgm_read_word_far(addr) pgm_read_word(addr) 20 | #define pgm_read_dword_far(addr) pgm_read_dword(addr) 21 | #define pgm_read_float_far(addr) pgm_read_float(addr) 22 | 23 | #define memcpy_P(to,from,len) memcpy(to,from,len) 24 | #endif 25 | -------------------------------------------------------------------------------- /cores/piduino/stdlib_noniso.h: -------------------------------------------------------------------------------- 1 | /* 2 | stdlib_noniso.h - nonstandard (but usefull) conversion functions 3 | 4 | Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 5 | This file is part of the esp8266 core for Arduino environment. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef STDLIB_NONISO_H 23 | #define STDLIB_NONISO_H 24 | 25 | #ifdef __cplusplus 26 | extern "C"{ 27 | #endif 28 | 29 | char* itoa (int val, char *s, int radix); 30 | 31 | char* ltoa (long val, char *s, int radix); 32 | 33 | char* utoa (unsigned int val, char *s, int radix); 34 | 35 | char* ultoa (unsigned long val, char *s, int radix); 36 | 37 | char* dtostrf (double val, signed char width, unsigned char prec, char *s); 38 | 39 | void reverse(char* begin, char* end); 40 | 41 | #ifdef __cplusplus 42 | } // extern "C" 43 | #endif 44 | 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /cores/piduino/wiring_digital.c: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino.c - Partial implementation of the Wiring API for the Raspberry Pi 3 | Copyright (c) 2015 Hristo Gochkov. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "Arduino.h" 21 | #include "bcm2835_registers.h" 22 | 23 | void pinMode(uint8_t pin, uint8_t mode){ 24 | GPFSEL(pin) &= ~(0x07 << GPFSELB(pin));//clear gpio function 25 | GPFSEL(pin) |= ((mode & 0x07) << GPFSELB(pin));//set function to pin 26 | if((mode & 0x07) == 0){//PULLUP/PULLDOWN 27 | mode &= 0x30; 28 | mode >>= 4; 29 | GPPUD = mode; 30 | delayMicroseconds(10); 31 | if(pin < 32) { 32 | GPPUDCLK0 = _BV(pin); 33 | } else if(pin < 46) { 34 | GPPUDCLK1 = _BV(pin - 32); 35 | } 36 | delayMicroseconds(10); 37 | GPPUD = 0; 38 | if(pin < 32) { 39 | GPPUDCLK0 = 0; 40 | } else if(pin < 46) { 41 | GPPUDCLK1 = 0; 42 | } 43 | } 44 | } 45 | 46 | void digitalWrite(uint8_t pin, uint8_t val){ 47 | if(pin < 32){ 48 | if(val) { 49 | GPSET0 = _BV(pin); 50 | } else { 51 | GPCLR0 = _BV(pin); 52 | } 53 | } else if(pin < 46){ 54 | if(val) { 55 | GPSET1 = _BV(pin - 32); 56 | } else { 57 | GPCLR1 = _BV(pin - 32); 58 | } 59 | } 60 | } 61 | 62 | int digitalRead(uint8_t pin){ 63 | if(pin < 32){ 64 | return (GPLEV0 & _BV(pin)) != 0; 65 | } else if(pin > 45) { 66 | return 0; 67 | } 68 | return (GPLEV1 & _BV(pin - 32)) != 0; 69 | } 70 | -------------------------------------------------------------------------------- /cores/piduino/wiring_ids.c: -------------------------------------------------------------------------------- 1 | /* 2 | I2C0 implementation for the Raspberry Pi 3 | Copyright (c) 2015 Hristo Gochkov. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "Arduino.h" 21 | #include "bcm2835_registers.h" 22 | 23 | void ids_begin(void){ 24 | pinMode(0, ALT0); 25 | pinMode(1, ALT0); 26 | BSC0DIV = BSCF2DIV(100000); 27 | } 28 | 29 | void ids_end(void){ 30 | pinMode(0, INPUT); 31 | pinMode(1, INPUT); 32 | } 33 | 34 | void ids_set_freq(uint32_t frequency){ 35 | BSC0DIV = BSCF2DIV(frequency); 36 | } 37 | 38 | uint8_t ids_write(uint8_t address, uint8_t * buf, uint32_t len){ 39 | uint32_t remaining = len; 40 | uint32_t i = 0; 41 | uint8_t reason = 0; 42 | 43 | BSC0A = address; 44 | BSC0C |= _BV(BSCCLEAR); 45 | BSC0S = _BV(BSCCLKT) | _BV(BSCERR) | _BV(BSCDONE); 46 | BSC0DLEN = len; 47 | while(remaining && ( i < 16 )){ 48 | BSC0FIFO = buf[i]; 49 | i++; 50 | remaining--; 51 | } 52 | 53 | BSC0C = _BV(BSCI2CEN) | _BV(BSCST); 54 | while(!(BSC0S & _BV(BSCDONE))){ 55 | while(remaining && (BSC0S & _BV(BSCTXD))){ 56 | BSC0FIFO = buf[i]; 57 | i++; 58 | remaining--; 59 | } 60 | } 61 | 62 | if (BSC0S & _BV(BSCERR)){ 63 | reason = 1; 64 | } else if (BSC0S & _BV(BSCCLKT)){ 65 | reason = 2; 66 | } else if (remaining){ 67 | reason = 3; 68 | } 69 | BSC0C |= _BV(BSCDONE); 70 | return reason; 71 | } 72 | 73 | uint8_t ids_read(uint8_t address, uint8_t* buf, uint32_t len){ 74 | uint32_t remaining = len; 75 | uint32_t i = 0; 76 | uint8_t reason = 0; 77 | 78 | BSC0A = address; 79 | BSC0C |= _BV(BSCCLEAR); 80 | BSC0S = _BV(BSCCLKT) | _BV(BSCERR) | _BV(BSCDONE); 81 | BSC0DLEN = len; 82 | BSC0C = _BV(BSCI2CEN) | _BV(BSCST) | _BV(BSCREAD); 83 | 84 | while(!(BSC0S & _BV(BSCDONE))){ 85 | while (BSC0S & _BV(BSCRXD)){ 86 | buf[i] = BSC0FIFO; 87 | i++; 88 | remaining--; 89 | } 90 | } 91 | 92 | while (remaining && (BSC0S & _BV(BSCRXD))){ 93 | buf[i] = BSC0FIFO; 94 | i++; 95 | remaining--; 96 | } 97 | 98 | if (BSC0S & _BV(BSCERR)){ 99 | reason = 1; 100 | } else if (BSC0S & _BV(BSCCLKT)){ 101 | reason = 2; 102 | } else if (remaining){ 103 | reason = 3; 104 | } 105 | BSC0C |= _BV(BSCDONE); 106 | return reason; 107 | } 108 | -------------------------------------------------------------------------------- /cores/piduino/wiring_int.c: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino.c - Partial implementation of the Wiring API for the Raspberry Pi 3 | Copyright (c) 2015 Hristo Gochkov. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "Arduino.h" 21 | #include "bcm2835_registers.h" 22 | 23 | typedef struct { 24 | uint8_t mode; 25 | void (*fn)(void); 26 | } isr_handler_t; 27 | 28 | pthread_t _pin_isr_thread; 29 | static isr_handler_t isr_handlers[64]; 30 | static volatile uint64_t _pin_isr_reg = 0; 31 | static volatile uint64_t _pin_isr_last = 0; 32 | 33 | void *isr_executor_task(void *isr_num){ 34 | isr_handler_t *handler = &isr_handlers[(int)isr_num]; 35 | handler->fn(); 36 | pthread_exit(NULL); 37 | } 38 | 39 | void *_isr_check_task(void *arg __attribute__((unused))){ 40 | while(_pin_isr_reg != 0){ 41 | uint64_t state = GPLEV0; 42 | if(_pin_isr_reg >> 32) { 43 | state |= (uint64_t)GPLEV1 << 32; 44 | } 45 | state &= _pin_isr_reg; 46 | int i = 0; 47 | uint32_t changed = state ^ _pin_isr_last; 48 | if(changed){ 49 | _pin_isr_last = state; 50 | while(changed){ 51 | while(!(changed & _BV(i))) { 52 | i++; 53 | } 54 | changed &= ~_BV(i); 55 | isr_handler_t *handler = &isr_handlers[i]; 56 | if((state & _BV(i)) == 0 && (handler->mode == FALLING || handler->mode == CHANGE) && handler->fn) { 57 | thread_create(isr_executor_task, (void *)i); 58 | } else if((state & _BV(i)) != 0 && (handler->mode == RISING || handler->mode == CHANGE) && handler->fn) { 59 | thread_create(isr_executor_task, (void *)i); 60 | } 61 | } 62 | } 63 | if(_pin_isr_reg > 0) 64 | usleep(100); 65 | } 66 | pthread_exit(NULL); 67 | } 68 | 69 | void attachInterrupt(uint8_t pin, void (*userFunc)(void), int mode) { 70 | if(pin < 46) { 71 | uint8_t start = _pin_isr_reg == 0; 72 | isr_handler_t *handler = &isr_handlers[pin]; 73 | handler->mode = mode; 74 | handler->fn = userFunc; 75 | _pin_isr_last |= (digitalRead(pin) << pin); 76 | _pin_isr_reg |= _BV(pin); 77 | if(start && pthread_create(&_pin_isr_thread, NULL, _isr_check_task, NULL) == 0){ 78 | pthread_setname_np(_pin_isr_thread, "arduino-isr"); 79 | pthread_detach(_pin_isr_thread); 80 | } 81 | } 82 | } 83 | 84 | void detachInterrupt(uint8_t pin) { 85 | if(pin < 46) { 86 | isr_handler_t *handler = &isr_handlers[pin]; 87 | _pin_isr_reg &= ~_BV(pin); 88 | handler->mode = 0; 89 | handler->fn = 0; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /cores/piduino/wiring_pulse.c: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino.c - Partial implementation of the Wiring API for the Raspberry Pi 3 | Copyright (c) 2015 Hristo Gochkov. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "Arduino.h" 21 | #include "bcm2835_registers.h" 22 | 23 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout){ 24 | pinMode(pin, INPUT); 25 | uint32_t start = micros(); 26 | while(digitalRead(pin) == state && (micros() - start) < timeout); 27 | while(digitalRead(pin) != state && (micros() - start) < timeout); 28 | start = micros(); 29 | while(digitalRead(pin) == state && (micros() - start) < timeout); 30 | return micros() - start; 31 | } 32 | -------------------------------------------------------------------------------- /cores/piduino/wiring_pwm.c: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino.c - Partial implementation of the Wiring API for the Raspberry Pi 3 | Copyright (c) 2015 Hristo Gochkov. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "Arduino.h" 21 | #include "bcm2835_registers.h" 22 | 23 | static uint32_t _pwm_range = PWM_RANGE; 24 | static uint32_t _pwm_wanted_freq = 1; 25 | static uint32_t _pwm_real_freq = 1; 26 | static uint8_t _pwm_has_started = 0; 27 | 28 | void analogWriteRange(uint32_t range){ 29 | _pwm_range = range; 30 | PWMRNG1 = _pwm_range; 31 | PWMRNG2 = _pwm_range; 32 | } 33 | 34 | void analogWriteDiv(uint16_t div){ 35 | GPPCTL = GPSRC_OSC + GPCPASS;//stop clock 36 | while(GPPCTL & (1 << GPBUSY));//wait if running 37 | GPPDIV = (div << GPDIVI) | GPCPASS;//set divider 38 | GPPCTL = (1 << GPENAB) | GPSRC_OSC | GPCPASS;//set ctrl 39 | } 40 | 41 | uint32_t analogWriteSetup(uint32_t frequency, uint32_t range){ 42 | _pwm_wanted_freq = frequency; 43 | uint32_t div = 19200000/(_pwm_wanted_freq*range); 44 | div += (div & 1) * 1; 45 | div &= 0xFFF; 46 | _pwm_real_freq = 19200000/(div*range); 47 | analogWriteRange(range); 48 | analogWriteDiv(div); 49 | return _pwm_real_freq; 50 | } 51 | 52 | void analogWriteInit(){ 53 | if(!_pwm_has_started){ 54 | _pwm_has_started = 1; 55 | _pwm_wanted_freq = analogWriteSetup(1000, 256); 56 | PWMCTL = 0; 57 | } 58 | } 59 | 60 | void analogWrite(uint8_t p, uint16_t v){ 61 | v = ((v*_pwm_real_freq)/_pwm_wanted_freq) % _pwm_range; 62 | if(v){ 63 | if(!_pwm_has_started) 64 | analogWriteInit(); 65 | if(p == 18 || p == 19){ 66 | pinMode(p, GPF5); 67 | } else if(p == 12 || p == 13 || p == 40 || p == 41 || p == 45){ 68 | pinMode(p, GPF0); 69 | } 70 | if(p == 12 || p == 18 || p == 40){ 71 | PWMCTL |= _BV(PWMPWEN1) | (1 << PWMMSEN1); 72 | PWMDAT1 = v; 73 | } else if(p == 13 || p == 19 || p == 41 || p == 45){ 74 | PWMCTL |= _BV(PWMPWEN2) | (1 << PWMMSEN2); 75 | PWMDAT2 = v; 76 | } 77 | } else { 78 | if(p == 12 || p == 18 || p == 40){ 79 | PWMCTL &= ~(_BV(PWMPWEN1) | (1 << PWMMSEN1)); 80 | PWMDAT1 = v; 81 | } else if(p == 13 || p == 19 || p == 41 || p == 45){ 82 | PWMCTL &= ~(_BV(PWMPWEN2) | (1 << PWMMSEN2)); 83 | PWMDAT2 = v; 84 | } 85 | if(p == 18 || p == 19){ 86 | pinMode(p, INPUT); 87 | } else if(p == 12 || p == 13 || p == 40 || p == 41 || p == 45){ 88 | pinMode(p, INPUT); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /cores/piduino/wiring_shift.c: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino.c - Partial implementation of the Wiring API for the Raspberry Pi 3 | Copyright (c) 2015 Hristo Gochkov. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "Arduino.h" 21 | #include "bcm2835_registers.h" 22 | 23 | uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) { 24 | uint8_t value = 0; 25 | uint8_t i; 26 | 27 | for (i = 0; i < 8; ++i) { 28 | digitalWrite(clockPin, HIGH); 29 | delayMicroseconds(1); 30 | if (bitOrder == LSBFIRST) { 31 | value |= digitalRead(dataPin) << i; 32 | } else { 33 | value |= digitalRead(dataPin) << (7 - i); 34 | } 35 | digitalWrite(clockPin, LOW); 36 | delayMicroseconds(1); 37 | } 38 | return value; 39 | } 40 | 41 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val){ 42 | uint8_t i; 43 | 44 | for (i = 0; i < 8; i++) { 45 | if (bitOrder == LSBFIRST) { 46 | digitalWrite(dataPin, !!(val & (1 << i))); 47 | } else { 48 | digitalWrite(dataPin, !!(val & (1 << (7 - i)))); 49 | } 50 | 51 | digitalWrite(clockPin, HIGH); 52 | delayMicroseconds(1); 53 | digitalWrite(clockPin, LOW); 54 | delayMicroseconds(1); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /cores/piduino/wiring_thread.c: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino.c - Partial implementation of the Wiring API for the Raspberry Pi 3 | Copyright (c) 2015 Hristo Gochkov. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "Arduino.h" 21 | #include "bcm2835_registers.h" 22 | #include 23 | 24 | static pthread_mutex_t thread_mutexes[10]; 25 | 26 | void thread_yield(){ 27 | pthread_yield(); 28 | } 29 | 30 | pthread_t thread_self(){ 31 | return pthread_self(); 32 | } 33 | 34 | pthread_t thread_create(thread_fn fn, void * arg){ 35 | pthread_t myThread ; 36 | if(pthread_create(&myThread, NULL, fn, arg) != 0) { 37 | return 0; 38 | } 39 | pthread_detach(myThread); 40 | return myThread; 41 | } 42 | 43 | int thread_set_name(pthread_t t, const char *name){ 44 | return pthread_setname_np(t, name); 45 | } 46 | 47 | int thread_set_priority(const int pri){ 48 | struct sched_param sched ; 49 | memset (&sched, 0, sizeof(sched)) ; 50 | if (pri > sched_get_priority_max(SCHED_OTHER)) { 51 | sched.sched_priority = sched_get_priority_max(SCHED_OTHER); 52 | } else { 53 | sched.sched_priority = pri ; 54 | } 55 | return sched_setscheduler(0, SCHED_OTHER, &sched) ; 56 | } 57 | 58 | int thread_detach(pthread_t t){ 59 | return pthread_detach(t); 60 | } 61 | 62 | int thread_terminate(pthread_t t){ 63 | return pthread_cancel(t); 64 | } 65 | 66 | uint8_t thread_running(pthread_t t){ 67 | int r = pthread_tryjoin_np(t, NULL); 68 | return (r==0 || r==EBUSY); 69 | } 70 | 71 | uint8_t thread_equals(pthread_t t){ 72 | return pthread_equal(pthread_self(),t); 73 | } 74 | 75 | void thread_lock(int index){ 76 | pthread_mutex_lock(&thread_mutexes[index]); 77 | } 78 | 79 | void thread_unlock(int index){ 80 | pthread_mutex_unlock(&thread_mutexes[index]); 81 | } 82 | -------------------------------------------------------------------------------- /doc/pi_monitor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me-no-dev/RasPiArduino/29fad57fa5d42cece2d5370831ba8f2a47b373c2/doc/pi_monitor.png -------------------------------------------------------------------------------- /doc/pi_pass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me-no-dev/RasPiArduino/29fad57fa5d42cece2d5370831ba8f2a47b373c2/doc/pi_pass.png -------------------------------------------------------------------------------- /doc/pi_select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me-no-dev/RasPiArduino/29fad57fa5d42cece2d5370831ba8f2a47b373c2/doc/pi_select.png -------------------------------------------------------------------------------- /libraries/Bridge/README.adoc: -------------------------------------------------------------------------------- 1 | = Bridge Library for Arduino = 2 | 3 | The Bridge library simplifies communication between the ATmega32U4 and the AR9331. 4 | 5 | For more information about this library please visit us at 6 | http://www.arduino.cc/en/Reference/YunBridgeLibrary 7 | 8 | == License == 9 | 10 | Copyright (c) 2014 Arduino LLC. All right reserved. 11 | 12 | This library is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | 17 | This library is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | Lesser General Public License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with this library; if not, write to the Free Software 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | -------------------------------------------------------------------------------- /libraries/Bridge/examples/ConsoleAsciiTable/ConsoleAsciiTable.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ASCII table 3 | 4 | Prints out byte values in all possible formats: 5 | * as raw binary values 6 | * as ASCII-encoded decimal, hex, octal, and binary values 7 | 8 | For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII 9 | 10 | The circuit: No external hardware needed. 11 | 12 | created 2006 13 | by Nicholas Zambetti 14 | http://www.zambetti.com 15 | modified 9 Apr 2012 16 | by Tom Igoe 17 | modified 22 May 2013 18 | by Cristian Maglie 19 | 20 | This example code is in the public domain. 21 | 22 | http://www.arduino.cc/en/Tutorial/ConsoleAsciiTable 23 | 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | void setup() { 30 | //Initialize Console and wait for port to open: 31 | Bridge.begin(); 32 | Console.begin(); 33 | 34 | // Uncomment the following line to enable buffering: 35 | // - better transmission speed and efficiency 36 | // - needs to call Console.flush() to ensure that all 37 | // transmitted data is sent 38 | 39 | //Console.buffer(64); 40 | 41 | while (!Console) { 42 | ; // wait for Console port to connect. 43 | } 44 | 45 | // prints title with ending line break 46 | Console.println("ASCII Table ~ Character Map"); 47 | } 48 | 49 | // first visible ASCIIcharacter '!' is number 33: 50 | int thisByte = 33; 51 | // you can also write ASCII characters in single quotes. 52 | // for example. '!' is the same as 33, so you could also use this: 53 | //int thisByte = '!'; 54 | 55 | void loop() { 56 | // prints value unaltered, i.e. the raw binary version of the 57 | // byte. The Console monitor interprets all bytes as 58 | // ASCII, so 33, the first number, will show up as '!' 59 | Console.write(thisByte); 60 | 61 | Console.print(", dec: "); 62 | // prints value as string as an ASCII-encoded decimal (base 10). 63 | // Decimal is the default format for Console.print() and Console.println(), 64 | // so no modifier is needed: 65 | Console.print(thisByte); 66 | // But you can declare the modifier for decimal if you want to. 67 | //this also works if you uncomment it: 68 | 69 | // Console.print(thisByte, DEC); 70 | 71 | Console.print(", hex: "); 72 | // prints value as string in hexadecimal (base 16): 73 | Console.print(thisByte, HEX); 74 | 75 | Console.print(", oct: "); 76 | // prints value as string in octal (base 8); 77 | Console.print(thisByte, OCT); 78 | 79 | Console.print(", bin: "); 80 | // prints value as string in binary (base 2) 81 | // also prints ending line break: 82 | Console.println(thisByte, BIN); 83 | 84 | // if printed last visible character '~' or 126, stop: 85 | if (thisByte == 126) { // you could also use if (thisByte == '~') { 86 | // ensure the latest bit of data is sent 87 | Console.flush(); 88 | 89 | // This loop loops forever and does nothing 90 | while (true) { 91 | continue; 92 | } 93 | } 94 | // go on to the next character 95 | thisByte++; 96 | } 97 | -------------------------------------------------------------------------------- /libraries/Bridge/examples/ConsolePixel/ConsolePixel.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Console Pixel 3 | 4 | An example of using the Arduino board to receive data from the 5 | Console on the Arduino Yún. In this case, the Arduino boards turns on an LED when 6 | it receives the character 'H', and turns off the LED when it 7 | receives the character 'L'. 8 | 9 | To see the Console, pick your Yún's name and IP address in the Port menu 10 | then open the Port Monitor. You can also see it by opening a terminal window 11 | and typing 12 | ssh root@ yourYunsName.local 'telnet localhost 6571' 13 | then pressing enter. When prompted for the password, enter it. 14 | 15 | 16 | The circuit: 17 | * LED connected from digital pin 13 to ground 18 | 19 | created 2006 20 | by David A. Mellis 21 | modified 25 Jun 2013 22 | by Tom Igoe 23 | 24 | This example code is in the public domain. 25 | 26 | http://www.arduino.cc/en/Tutorial/ConsolePixel 27 | 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | const int ledPin = 13; // the pin that the LED is attached to 34 | char incomingByte; // a variable to read incoming Console data into 35 | 36 | void setup() { 37 | Bridge.begin(); // Initialize Bridge 38 | Console.begin(); // Initialize Console 39 | 40 | // Wait for the Console port to connect 41 | while (!Console); 42 | 43 | Console.println("type H or L to turn pin 13 on or off"); 44 | 45 | // initialize the LED pin as an output: 46 | pinMode(ledPin, OUTPUT); 47 | } 48 | 49 | void loop() { 50 | // see if there's incoming Console data: 51 | if (Console.available() > 0) { 52 | // read the oldest byte in the Console buffer: 53 | incomingByte = Console.read(); 54 | Console.println(incomingByte); 55 | // if it's a capital H (ASCII 72), turn on the LED: 56 | if (incomingByte == 'H') { 57 | digitalWrite(ledPin, HIGH); 58 | } 59 | // if it's an L (ASCII 76) turn off the LED: 60 | if (incomingByte == 'L') { 61 | digitalWrite(ledPin, LOW); 62 | } 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Console Read example 3 | 4 | Read data coming from bridge using the Console.read() function 5 | and store it in a string. 6 | 7 | To see the Console, pick your Yún's name and IP address in the Port menu 8 | then open the Port Monitor. You can also see it by opening a terminal window 9 | and typing: 10 | ssh root@ yourYunsName.local 'telnet localhost 6571' 11 | then pressing enter. When prompted for the password, enter it. 12 | 13 | created 13 Jun 2013 14 | by Angelo Scialabba 15 | modified 16 June 2013 16 | by Tom Igoe 17 | 18 | This example code is in the public domain. 19 | 20 | http://www.arduino.cc/en/Tutorial/ConsoleRead 21 | 22 | */ 23 | 24 | #include 25 | #include 26 | 27 | String name; 28 | 29 | void setup() { 30 | // Initialize Console and wait for port to open: 31 | Bridge.begin(); 32 | Console.begin(); 33 | 34 | // Wait for Console port to connect 35 | while (!Console); 36 | 37 | Console.println("Hi, what's your name?"); 38 | } 39 | 40 | void loop() { 41 | if (Console.available() > 0) { 42 | char c = Console.read(); // read the next char received 43 | // look for the newline character, this is the last character in the string 44 | if (c == '\n') { 45 | //print text with the name received 46 | Console.print("Hi "); 47 | Console.print(name); 48 | Console.println("! Nice to meet you!"); 49 | Console.println(); 50 | // Ask again for name and clear the old name 51 | Console.println("Hi, what's your name?"); 52 | name = ""; // clear the name string 53 | } else { // if the buffer is empty Cosole.read() returns -1 54 | name += c; // append the read char from Console to the name string 55 | } 56 | } else { 57 | delay(100); 58 | } 59 | } 60 | 61 | 62 | -------------------------------------------------------------------------------- /libraries/Bridge/examples/Datalogger/Datalogger.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card datalogger 3 | 4 | This example shows how to log data from three analog sensors 5 | to an SD card mounted on the Arduino Yún using the Bridge library. 6 | 7 | The circuit: 8 | * analog sensors on analog pins 0, 1 and 2 9 | * SD card attached to SD card slot of the Arduino Yún 10 | 11 | Prepare your SD card creating an empty folder in the SD root 12 | named "arduino". This will ensure that the Yún will create a link 13 | to the SD to the "/mnt/sd" path. 14 | 15 | You can remove the SD card while the Linux and the 16 | sketch are running but be careful not to remove it while 17 | the system is writing to it. 18 | 19 | created 24 Nov 2010 20 | modified 9 Apr 2012 21 | by Tom Igoe 22 | adapted to the Yún Bridge library 20 Jun 2013 23 | by Federico Vanzati 24 | modified 21 Jun 2013 25 | by Tom Igoe 26 | 27 | This example code is in the public domain. 28 | 29 | http://www.arduino.cc/en/Tutorial/YunDatalogger 30 | 31 | */ 32 | 33 | #include 34 | 35 | void setup() { 36 | // Initialize the Bridge and the Serial 37 | Bridge.begin(); 38 | Serial.begin(9600); 39 | FileSystem.begin(); 40 | 41 | while (!Serial); // wait for Serial port to connect. 42 | Serial.println("Filesystem datalogger\n"); 43 | } 44 | 45 | 46 | void loop() { 47 | // make a string that start with a timestamp for assembling the data to log: 48 | String dataString; 49 | dataString += getTimeStamp(); 50 | dataString += " = "; 51 | 52 | // read three sensors and append to the string: 53 | for (int analogPin = 0; analogPin < 3; analogPin++) { 54 | int sensor = analogRead(analogPin); 55 | dataString += String(sensor); 56 | if (analogPin < 2) { 57 | dataString += ","; // separate the values with a comma 58 | } 59 | } 60 | 61 | // open the file. note that only one file can be open at a time, 62 | // so you have to close this one before opening another. 63 | // The FileSystem card is mounted at the following "/mnt/FileSystema1" 64 | File dataFile = FileSystem.open("/mnt/sd/datalog.txt", FILE_APPEND); 65 | 66 | // if the file is available, write to it: 67 | if (dataFile) { 68 | dataFile.println(dataString); 69 | dataFile.close(); 70 | // print to the serial port too: 71 | Serial.println(dataString); 72 | } 73 | // if the file isn't open, pop up an error: 74 | else { 75 | Serial.println("error opening datalog.txt"); 76 | } 77 | 78 | delay(15000); 79 | 80 | } 81 | 82 | // This function return a string with the time stamp 83 | String getTimeStamp() { 84 | String result; 85 | Process time; 86 | // date is a command line utility to get the date and the time 87 | // in different formats depending on the additional parameter 88 | time.begin("date"); 89 | time.addParameter("+%D-%T"); // parameters: D for the complete date mm/dd/yy 90 | // T for the time hh:mm:ss 91 | time.run(); // run the command 92 | 93 | // read the output of the command 94 | while (time.available() > 0) { 95 | char c = time.read(); 96 | if (c != '\n') { 97 | result += c; 98 | } 99 | } 100 | 101 | return result; 102 | } 103 | -------------------------------------------------------------------------------- /libraries/Bridge/examples/FileWriteScript/FileWriteScript.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Write to file using FileIO classes. 3 | 4 | This sketch demonstrate how to write file into the Yún filesystem. 5 | A shell script file is created in /tmp, and it is executed afterwards. 6 | 7 | created 7 June 2010 8 | by Cristian Maglie 9 | 10 | This example code is in the public domain. 11 | 12 | http://www.arduino.cc/en/Tutorial/FileWriteScript 13 | 14 | */ 15 | 16 | #include 17 | 18 | void setup() { 19 | // Setup Bridge (needed every time we communicate with the Arduino Yún) 20 | Bridge.begin(); 21 | // Initialize the Serial 22 | Serial.begin(9600); 23 | 24 | while (!Serial); // wait for Serial port to connect. 25 | Serial.println("File Write Script example\n\n"); 26 | 27 | // Setup File IO 28 | FileSystem.begin(); 29 | 30 | // Upload script used to gain network statistics 31 | uploadScript(); 32 | } 33 | 34 | void loop() { 35 | // Run stats script every 5 secs. 36 | runScript(); 37 | delay(5000); 38 | } 39 | 40 | // this function creates a file into the linux processor that contains a shell script 41 | // to check the network traffic of the WiFi interface 42 | void uploadScript() { 43 | // Write our shell script in /tmp 44 | // Using /tmp stores the script in RAM this way we can preserve 45 | // the limited amount of FLASH erase/write cycles 46 | File script = FileSystem.open("/tmp/wlan-stats.sh", FILE_WRITE); 47 | // Shell script header 48 | script.print("#!/bin/sh\n"); 49 | // shell commands: 50 | // ifconfig: is a command line utility for controlling the network interfaces. 51 | // wlan0 is the interface we want to query 52 | // grep: search inside the output of the ifconfig command the "RX bytes" keyword 53 | // and extract the line that contains it 54 | script.print("ifconfig wlan0 | grep 'RX bytes'\n"); 55 | script.close(); // close the file 56 | 57 | // Make the script executable 58 | Process chmod; 59 | chmod.begin("chmod"); // chmod: change mode 60 | chmod.addParameter("+x"); // x stays for executable 61 | chmod.addParameter("/tmp/wlan-stats.sh"); // path to the file to make it executable 62 | chmod.run(); 63 | } 64 | 65 | 66 | // this function run the script and read the output data 67 | void runScript() { 68 | // Run the script and show results on the Serial 69 | Process myscript; 70 | myscript.begin("/tmp/wlan-stats.sh"); 71 | myscript.run(); 72 | 73 | String output = ""; 74 | 75 | // read the output of the script 76 | while (myscript.available()) { 77 | output += (char)myscript.read(); 78 | } 79 | // remove the blank spaces at the beginning and the ending of the string 80 | output.trim(); 81 | Serial.println(output); 82 | Serial.flush(); 83 | } 84 | 85 | -------------------------------------------------------------------------------- /libraries/Bridge/examples/HttpClient/HttpClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Yún HTTP Client 3 | 4 | This example for the Arduino Yún shows how create a basic 5 | HTTP client that connects to the internet and downloads 6 | content. In this case, you'll connect to the Arduino 7 | website and download a version of the logo as ASCII text. 8 | 9 | created by Tom igoe 10 | May 2013 11 | 12 | This example code is in the public domain. 13 | 14 | http://www.arduino.cc/en/Tutorial/HttpClient 15 | 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | void setup() { 22 | // Bridge takes about two seconds to start up 23 | // it can be helpful to use the on-board LED 24 | // as an indicator for when it has initialized 25 | pinMode(13, OUTPUT); 26 | digitalWrite(13, LOW); 27 | Bridge.begin(); 28 | digitalWrite(13, HIGH); 29 | 30 | Serial.begin(9600); 31 | 32 | while (!Serial); // wait for a serial connection 33 | } 34 | 35 | void loop() { 36 | // Initialize the client library 37 | HttpClient client; 38 | 39 | // Make a HTTP request: 40 | client.get("http://www.arduino.cc/asciilogo.txt"); 41 | 42 | // if there are incoming bytes available 43 | // from the server, read them and print them: 44 | while (client.available()) { 45 | char c = client.read(); 46 | Serial.print(c); 47 | } 48 | Serial.flush(); 49 | 50 | delay(5000); 51 | } 52 | 53 | 54 | -------------------------------------------------------------------------------- /libraries/Bridge/examples/Process/Process.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Running process using Process class. 3 | 4 | This sketch demonstrate how to run linux processes 5 | using an Arduino Yún. 6 | 7 | created 5 Jun 2013 8 | by Cristian Maglie 9 | 10 | This example code is in the public domain. 11 | 12 | http://www.arduino.cc/en/Tutorial/Process 13 | 14 | */ 15 | 16 | #include 17 | 18 | void setup() { 19 | // Initialize Bridge 20 | Bridge.begin(); 21 | 22 | // Initialize Serial 23 | Serial.begin(9600); 24 | 25 | // Wait until a Serial Monitor is connected. 26 | while (!Serial); 27 | 28 | // run various example processes 29 | runCurl(); 30 | runCpuInfo(); 31 | } 32 | 33 | void loop() { 34 | // Do nothing here. 35 | } 36 | 37 | void runCurl() { 38 | // Launch "curl" command and get Arduino ascii art logo from the network 39 | // curl is command line program for transferring data using different internet protocols 40 | Process p; // Create a process and call it "p" 41 | p.begin("curl"); // Process that launch the "curl" command 42 | p.addParameter("http://www.arduino.cc/asciilogo.txt"); // Add the URL parameter to "curl" 43 | p.run(); // Run the process and wait for its termination 44 | 45 | // Print arduino logo over the Serial 46 | // A process output can be read with the stream methods 47 | while (p.available() > 0) { 48 | char c = p.read(); 49 | Serial.print(c); 50 | } 51 | // Ensure the last bit of data is sent. 52 | Serial.flush(); 53 | } 54 | 55 | void runCpuInfo() { 56 | // Launch "cat /proc/cpuinfo" command (shows info on Atheros CPU) 57 | // cat is a command line utility that shows the content of a file 58 | Process p; // Create a process and call it "p" 59 | p.begin("cat"); // Process that launch the "cat" command 60 | p.addParameter("/proc/cpuinfo"); // Add the cpuifo file path as parameter to cut 61 | p.run(); // Run the process and wait for its termination 62 | 63 | // Print command output on the Serial. 64 | // A process output can be read with the stream methods 65 | while (p.available() > 0) { 66 | char c = p.read(); 67 | Serial.print(c); 68 | } 69 | // Ensure the last bit of data is sent. 70 | Serial.flush(); 71 | } 72 | 73 | -------------------------------------------------------------------------------- /libraries/Bridge/examples/ShellCommands/ShellCommands.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Running shell commands using Process class. 3 | 4 | This sketch demonstrate how to run linux shell commands 5 | using an Arduino Yún. It runs the wifiCheck script on the Linux side 6 | of the Yún, then uses grep to get just the signal strength line. 7 | Then it uses parseInt() to read the wifi signal strength as an integer, 8 | and finally uses that number to fade an LED using analogWrite(). 9 | 10 | The circuit: 11 | * Arduino Yún with LED connected to pin 9 12 | 13 | created 12 Jun 2013 14 | by Cristian Maglie 15 | modified 25 June 2013 16 | by Tom Igoe 17 | 18 | This example code is in the public domain. 19 | 20 | http://www.arduino.cc/en/Tutorial/ShellCommands 21 | 22 | */ 23 | 24 | #include 25 | 26 | void setup() { 27 | Bridge.begin(); // Initialize the Bridge 28 | Serial.begin(9600); // Initialize the Serial 29 | 30 | // Wait until a Serial Monitor is connected. 31 | while (!Serial); 32 | } 33 | 34 | void loop() { 35 | Process p; 36 | // This command line runs the WifiStatus script, (/usr/bin/pretty-wifi-info.lua), then 37 | // sends the result to the grep command to look for a line containing the word 38 | // "Signal:" the result is passed to this sketch: 39 | p.runShellCommand("/usr/bin/pretty-wifi-info.lua | grep Signal"); 40 | 41 | // do nothing until the process finishes, so you get the whole output: 42 | while (p.running()); 43 | 44 | // Read command output. runShellCommand() should have passed "Signal: xx&": 45 | while (p.available()) { 46 | int result = p.parseInt(); // look for an integer 47 | int signal = map(result, 0, 100, 0, 255); // map result from 0-100 range to 0-255 48 | analogWrite(9, signal); // set the brightness of LED on pin 9 49 | Serial.println(result); // print the number as well 50 | } 51 | delay(5000); // wait 5 seconds before you do it again 52 | } 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /libraries/Bridge/examples/TemperatureWebPanel/www/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 13 | 0 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /libraries/Bridge/examples/TimeCheck/TimeCheck.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Time Check 3 | 4 | Gets the time from Linux via Bridge then parses out hours, 5 | minutes and seconds for the Arduino using an Arduino Yún. 6 | 7 | created 27 May 2013 8 | modified 21 June 2013 9 | By Tom Igoe 10 | 11 | This example code is in the public domain. 12 | 13 | http://www.arduino.cc/en/Tutorial/TimeCheck 14 | 15 | */ 16 | 17 | 18 | #include 19 | 20 | Process date; // process used to get the date 21 | int hours, minutes, seconds; // for the results 22 | int lastSecond = -1; // need an impossible value for comparison 23 | 24 | void setup() { 25 | Bridge.begin(); // initialize Bridge 26 | Serial.begin(9600); // initialize serial 27 | 28 | while (!Serial); // wait for Serial Monitor to open 29 | Serial.println("Time Check"); // Title of sketch 30 | 31 | // run an initial date process. Should return: 32 | // hh:mm:ss : 33 | if (!date.running()) { 34 | date.begin("date"); 35 | date.addParameter("+%T"); 36 | date.run(); 37 | } 38 | } 39 | 40 | void loop() { 41 | 42 | if (lastSecond != seconds) { // if a second has passed 43 | // print the time: 44 | if (hours <= 9) { 45 | Serial.print("0"); // adjust for 0-9 46 | } 47 | Serial.print(hours); 48 | Serial.print(":"); 49 | if (minutes <= 9) { 50 | Serial.print("0"); // adjust for 0-9 51 | } 52 | Serial.print(minutes); 53 | Serial.print(":"); 54 | if (seconds <= 9) { 55 | Serial.print("0"); // adjust for 0-9 56 | } 57 | Serial.println(seconds); 58 | 59 | // restart the date process: 60 | if (!date.running()) { 61 | date.begin("date"); 62 | date.addParameter("+%T"); 63 | date.run(); 64 | } 65 | } 66 | 67 | //if there's a result from the date process, parse it: 68 | while (date.available() > 0) { 69 | // get the result of the date process (should be hh:mm:ss): 70 | String timeString = date.readString(); 71 | 72 | // find the colons: 73 | int firstColon = timeString.indexOf(":"); 74 | int secondColon = timeString.lastIndexOf(":"); 75 | 76 | // get the substrings for hour, minute second: 77 | String hourString = timeString.substring(0, firstColon); 78 | String minString = timeString.substring(firstColon + 1, secondColon); 79 | String secString = timeString.substring(secondColon + 1); 80 | 81 | // convert to ints,saving the previous second: 82 | hours = hourString.toInt(); 83 | minutes = minString.toInt(); 84 | lastSecond = seconds; // save to do a time comparison 85 | seconds = secString.toInt(); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /libraries/Bridge/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Bridge 3 | ####################################### 4 | 5 | ####################################### 6 | # Class (KEYWORD1) 7 | ####################################### 8 | 9 | Bridge KEYWORD1 YunBridgeLibrary 10 | FileIO KEYWORD4 YunFileIOConstructor 11 | FileSystem KEYWORD1 YunFileIOConstructor 12 | Console KEYWORD1 YunConsoleConstructor 13 | Process KEYWORD1 YunProcessConstructor 14 | Mailbox KEYWORD1 YunMailboxConstructor 15 | HttpClient KEYWORD1 YunHttpClientConstructor 16 | YunServer KEYWORD1 YunServerConstructor 17 | YunClient KEYWORD1 YunClientConstructor 18 | BridgeServer KEYWORD1 YunServerConstructor 19 | BridgeClient KEYWORD1 YunClientConstructor 20 | 21 | ####################################### 22 | # Methods and Functions (KEYWORD2) 23 | ####################################### 24 | 25 | # methods names in commond 26 | begin KEYWORD2 27 | end KEYWORD2 28 | available KEYWORD2 29 | read KEYWORD2 30 | peek KEYWORD2 31 | write KEYWORD2 32 | flush KEYWORD2 33 | bool KEYWORD2 34 | 35 | # Bridge Class 36 | transfer KEYWORD2 37 | put KEYWORD2 38 | get KEYWORD2 39 | 40 | # Console Class 41 | buffer KEYWORD2 42 | noBuffer KEYWORD2 43 | connected KEYWORD2 44 | 45 | # FileIO Class 46 | File KEYWORD2 47 | BridgeFile KEYWORD2 48 | seek KEYWORD2 49 | position KEYWORD2 50 | size KEYWORD2 51 | close KEYWORD2 52 | name KEYWORD2 53 | isDirectory KEYWORD2 54 | openNextFile KEYWORD2 55 | rewindDirectory KEYWORD2 56 | 57 | # Process Class 58 | addParameter KEYWORD2 59 | runAsynchronously KEYWORD2 60 | run KEYWORD2 61 | running KEYWORD2 62 | exitValue KEYWORD2 63 | runShellCommand KEYWORD2 64 | runShellCommandAsynchronously KEYWORD2 65 | 66 | # Mailbox Class 67 | readMessage KEYWORD2 68 | writeMessage KEYWORD2 69 | writeJSON KEYWORD2 70 | message Available KEYWORD2 71 | 72 | # HttpClient Class 73 | getAsynchronously KEYWORD2 74 | ready KEYWORD2 75 | getResult KEYWORD2 76 | 77 | # BridgeServer Class 78 | accept KEYWORD2 79 | stop KEYWORD2 80 | connect KEYWORD2 81 | connected KEYWORD2 82 | 83 | 84 | ####################################### 85 | # Constants (LITERAL1) 86 | ####################################### 87 | 88 | FILE_READ LITERAL1 89 | FILE_WRITE LITERAL1 90 | FILE_APPEND LITERAL1 91 | -------------------------------------------------------------------------------- /libraries/Bridge/library.properties: -------------------------------------------------------------------------------- 1 | name=Bridge 2 | version=1.6.0 3 | author=Arduino 4 | maintainer=Arduino 5 | sentence=Enables the communication between the Linux processor and the AVR. For Arduino Yún and TRE only. 6 | paragraph=The Bridge library feature: access to the shared storage, run and manage linux processes, open a remote console, access to the linux file system, including the SD card, enstablish http clients or servers. 7 | category=Communication 8 | url=http://www.arduino.cc/en/Reference/YunBridgeLibrary 9 | architectures=* 10 | -------------------------------------------------------------------------------- /libraries/Bridge/src/Bridge.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 Arduino LLC. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include "Bridge.h" 20 | 21 | BridgeClass::BridgeClass(Stream &_stream){} 22 | 23 | void BridgeClass::begin() {} 24 | 25 | void BridgeClass::put(const char *key, const char *value) {} 26 | 27 | unsigned int BridgeClass::get(const char *key, uint8_t *value, unsigned int maxlen) { 28 | return 0; 29 | } 30 | 31 | void checkForRemoteSketchUpdate(uint8_t pin) {} 32 | 33 | SerialBridgeClass Bridge(Serial); 34 | 35 | -------------------------------------------------------------------------------- /libraries/Bridge/src/Bridge.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 Arduino LLC. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef BRIDGE_H_ 20 | #define BRIDGE_H_ 21 | 22 | #include 23 | #include 24 | 25 | class BridgeClass { 26 | public: 27 | BridgeClass(Stream &_stream); 28 | void begin(); 29 | 30 | // Methods to handle key/value datastore 31 | void put(const char *key, const char *value); 32 | void put(const String &key, const String &value){ 33 | put(key.c_str(), value.c_str()); 34 | } 35 | unsigned int get(const char *key, uint8_t *buff, unsigned int size); 36 | unsigned int get(const char *key, char *value, unsigned int maxlen){ 37 | return get(key, reinterpret_cast(value), maxlen); 38 | } 39 | uint16_t getBridgeVersion(){ 40 | return 0; 41 | } 42 | }; 43 | 44 | // This subclass uses a serial port Stream 45 | class SerialBridgeClass : public BridgeClass { 46 | public: 47 | SerialBridgeClass(Stream &_serial) : BridgeClass(_serial) { 48 | // Empty 49 | } 50 | void begin(unsigned long baudrate=0) { 51 | BridgeClass::begin(); 52 | } 53 | }; 54 | 55 | extern SerialBridgeClass Bridge; 56 | extern void checkForRemoteSketchUpdate(uint8_t pin=0); 57 | 58 | #endif /* BRIDGE_H_ */ 59 | 60 | #include 61 | #include 62 | -------------------------------------------------------------------------------- /libraries/Bridge/src/BridgeClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | Client.h - Base class that provides Client 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef pi_client_h 21 | #define pi_client_h 22 | 23 | #include "Arduino.h" 24 | #include "Client.h" 25 | 26 | class BridgeClient : public Client { 27 | protected: 28 | int sockfd; 29 | bool _connected; 30 | 31 | public: 32 | BridgeClient *next; 33 | BridgeClient():sockfd(-1),_connected(false),next(NULL){} 34 | BridgeClient(int fd):sockfd(fd),_connected(true),next(NULL){} 35 | ~BridgeClient(); 36 | virtual int connect(IPAddress ip, uint16_t port); 37 | virtual int connect(const char *host, uint16_t port); 38 | virtual size_t write(uint8_t data); 39 | virtual size_t write(const uint8_t *buf, size_t size); 40 | virtual int available(); 41 | virtual int read(); 42 | virtual int read(uint8_t *buf, size_t size); 43 | virtual int peek(){return 0;} 44 | virtual void flush(){} 45 | virtual void stop(); 46 | virtual uint8_t connected(); 47 | virtual operator bool(){ return connected(); } 48 | virtual bool operator==(const bool value) { return bool() == value; } 49 | virtual bool operator!=(const bool value) { return bool() != value; } 50 | virtual bool operator==(const BridgeClient&); 51 | virtual bool operator!=(const BridgeClient& rhs) { return !this->operator==(rhs); }; 52 | 53 | int fd(){return sockfd;} 54 | IPAddress remoteIP(); 55 | uint16_t remotePort(); 56 | int setSocketOption(int option, char* value, size_t len); 57 | int setOption(int option, int *value); 58 | int getOption(int option, int *value); 59 | int setTimeout(uint32_t seconds); 60 | int setNoDelay(bool nodelay); 61 | bool getNoDelay(); 62 | 63 | static IPAddress remoteIP(int fd); 64 | static uint16_t remotePort(int fd); 65 | 66 | friend class BridgeServer; 67 | using Print::write; 68 | }; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /libraries/Bridge/src/BridgeServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Server.h - Server class for Raspberry Pi 3 | Copyright (c) 2016 Hristo Gochkov All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef pi_server_h 21 | #define pi_server_h 22 | 23 | #include "Arduino.h" 24 | #include "Server.h" 25 | #include "BridgeClient.h" 26 | 27 | typedef void(*BridgeServerHandler)(Client&); 28 | 29 | class BridgeServer : public Server { 30 | private: 31 | int sockfd; 32 | int pollfd; 33 | struct epoll_event *events; 34 | uint16_t _port; 35 | uint8_t _max_clients; 36 | bool _listening; 37 | BridgeServerHandler _cb; 38 | BridgeClient *clients; 39 | 40 | //cleans all disconnected clients 41 | void cleanup(); 42 | int setSocketOption(int option, char* value, size_t len); 43 | 44 | public: 45 | void listenOnLocalhost(){} 46 | 47 | BridgeServer(uint16_t port=80, uint8_t max_clients=8):sockfd(-1),pollfd(0),events(NULL),_port(port),_max_clients(max_clients),_listening(false),_cb(NULL),clients(NULL){} 48 | ~BridgeServer(){ end();} 49 | BridgeClient available(); 50 | BridgeClient accept(){return available();} 51 | virtual void begin(); 52 | virtual size_t write(const uint8_t *data, size_t len); 53 | virtual size_t write(uint8_t data){ 54 | return write(&data, 1); 55 | } 56 | using Print::write; 57 | 58 | void end(); 59 | operator bool(){return _listening;} 60 | int setTimeout(uint32_t seconds); 61 | BridgeClient *clientByFd(int fd){ 62 | BridgeClient *c = clients; 63 | while(c != NULL && c->fd() != fd) c = c->next; 64 | return c; 65 | } 66 | void stopAll(); 67 | }; 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /libraries/Bridge/src/BridgeUdp.h: -------------------------------------------------------------------------------- 1 | #ifndef pi_udp_h 2 | #define pi_udp_h 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class BridgeUDP : public UDP { 9 | private: 10 | int udp_server; 11 | IPAddress multicast_ip; 12 | IPAddress remote_ip; 13 | uint16_t remote_port; 14 | char buffer[1460]; 15 | size_t buffer_len; 16 | cbuf * rx_buffer; 17 | public: 18 | BridgeUDP():udp_server(-1), remote_port(0), buffer_len(0), rx_buffer(0){} 19 | ~BridgeUDP(){ 20 | stop(); 21 | if(rx_buffer) 22 | delete rx_buffer; 23 | } 24 | virtual uint8_t begin(uint16_t); 25 | virtual uint8_t beginMulticast(IPAddress a, uint16_t p){ 26 | multicast_ip = a; 27 | return begin(p); 28 | } 29 | virtual void stop(); 30 | virtual int beginPacket(); 31 | virtual int beginPacket(IPAddress ip, uint16_t port); 32 | virtual int beginPacket(const char *host, uint16_t port); 33 | virtual int endPacket(); 34 | virtual size_t write(uint8_t); 35 | virtual size_t write(const uint8_t *buffer, size_t size); 36 | virtual int parsePacket(); 37 | virtual int available(); 38 | virtual int read(); 39 | virtual int read(unsigned char* buffer, size_t len); 40 | virtual int read(char* buffer, size_t len); 41 | virtual int peek(); 42 | virtual void flush(); 43 | virtual IPAddress remoteIP(); 44 | virtual uint16_t remotePort(); 45 | }; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /libraries/Bridge/src/FileIO.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 Arduino LLC. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef __FILEIO_H__ 20 | #define __FILEIO_H__ 21 | 22 | #include 23 | #include 24 | 25 | #define FILE_READ "r" 26 | #define FILE_WRITE "r+" 27 | #define FILE_APPEND "a" 28 | #define FILE_CREATE "w+" 29 | 30 | namespace BridgeLib { 31 | 32 | class File : public Stream { 33 | private: 34 | FILE *_file; 35 | DIR *_dir; 36 | char *_name; 37 | 38 | public: 39 | File(BridgeClass &b = Bridge); 40 | File(const char *_filename, const char * _mode, BridgeClass &b = Bridge); 41 | ~File(); 42 | 43 | virtual size_t write(uint8_t); 44 | virtual size_t write(const uint8_t *buf, size_t size); 45 | virtual int read(); 46 | virtual int peek(); 47 | virtual int available(); 48 | virtual void flush(); 49 | int read(void *buf, uint16_t nbyte); 50 | boolean seek(uint32_t pos); 51 | uint32_t position(); 52 | uint32_t size(); 53 | void close(); 54 | operator bool(); 55 | const char * name(); 56 | boolean isDirectory(); 57 | File openNextFile(const char * mode = FILE_READ); 58 | void rewindDirectory(void); 59 | 60 | //using Print::write; 61 | }; 62 | 63 | class FileSystemClass { 64 | public: 65 | FileSystemClass(BridgeClass &_b = Bridge) { } 66 | 67 | boolean begin(); 68 | 69 | // Open the specified file/directory with the supplied mode (e.g. read or 70 | // write, etc). Returns a File object for interacting with the file. 71 | // Note that currently only one file can be open at a time. 72 | File open(const char *filename, const char * mode = FILE_READ); 73 | 74 | // Methods to determine if the requested file path exists. 75 | boolean exists(const char *filepath); 76 | 77 | // Create the requested directory hierarchy--if intermediate directories 78 | // do not exist they will be created. 79 | boolean mkdir(const char *filepath); 80 | 81 | // Delete the file. 82 | boolean remove(const char *filepath); 83 | 84 | boolean rmdir(const char *filepath); 85 | 86 | private: 87 | friend class File; 88 | }; 89 | 90 | extern FileSystemClass FileSystem; 91 | 92 | }; 93 | 94 | // We enclose File and FileSystem classes in namespace BridgeLib to avoid 95 | // conflicts with legacy SD library. 96 | 97 | // This ensure compatibility with older sketches that uses only Bridge lib 98 | // (the user can still use File instead of BridgeFile) 99 | using namespace BridgeLib; 100 | 101 | // This allows sketches to use BridgeLib::File together with SD library 102 | // (you must use BridgeFile instead of File when needed to disambiguate) 103 | typedef BridgeLib::File BridgeFile; 104 | typedef BridgeLib::FileSystemClass BridgeFileSystemClass; 105 | #define BridgeFileSystem BridgeLib::FileSystem 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /libraries/Bridge/src/HttpClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2014 Arduino LLC. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef HTTPCLIENT_H_ 20 | #define HTTPCLIENT_H_ 21 | 22 | #include 23 | 24 | class HttpClient : public Process { 25 | public: 26 | HttpClient(); 27 | 28 | unsigned int get(String &url); 29 | unsigned int get(const char * url); 30 | void getAsynchronously(String &url); 31 | void getAsynchronously(const char * url); 32 | unsigned int post(String &url, String &data); 33 | unsigned int post(const char * url, const char * data); 34 | void postAsynchronously(String &url, String &data); 35 | void postAsynchronously(const char * url, const char * data); 36 | unsigned int patch(String &url, String &data); 37 | unsigned int patch(const char * url, const char * data); 38 | void patchAsynchronously(String &url, String &data); 39 | void patchAsynchronously(const char * url, const char * data); 40 | unsigned int put(String &url, String &data); 41 | unsigned int put(const char * url, const char * data); 42 | void putAsynchronously(String &url, String &data); 43 | void putAsynchronously(const char * url, const char * data); 44 | void setHeader(String &header); 45 | void setHeader(const char * header); 46 | boolean ready(); 47 | unsigned int getResult(); 48 | void noCheckSSL(); 49 | void checkSSL(); 50 | 51 | private: 52 | boolean insecure; 53 | 54 | private: 55 | void addHeader(); 56 | String header; 57 | }; 58 | 59 | #endif /* HTTPCLIENT_H_ */ 60 | -------------------------------------------------------------------------------- /libraries/Bridge/src/Mailbox.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 Arduino LLC. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include 20 | 21 | unsigned int MailboxClass::readMessage(uint8_t *buff, unsigned int size) { return 0; } 22 | 23 | void MailboxClass::readMessage(String &str, unsigned int maxLength) {} 24 | 25 | void MailboxClass::writeMessage(const uint8_t *buff, unsigned int size) {} 26 | 27 | void MailboxClass::writeMessage(const String& str) { 28 | writeMessage((uint8_t*) str.c_str(), str.length()); 29 | } 30 | 31 | void MailboxClass::writeJSON(const String& str) {} 32 | 33 | unsigned int MailboxClass::messageAvailable() { 34 | return 0; 35 | } 36 | 37 | MailboxClass Mailbox(Bridge); 38 | -------------------------------------------------------------------------------- /libraries/Bridge/src/Mailbox.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 Arduino LLC. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _MAILBOX_CLASS_H_INCLUDED_ 20 | #define _MAILBOX_CLASS_H_INCLUDED_ 21 | 22 | #include 23 | 24 | class MailboxClass { 25 | public: 26 | MailboxClass(BridgeClass &b = Bridge) : bridge(b) { } 27 | 28 | void begin() { } 29 | void end() { } 30 | 31 | // Receive a message and store it inside a buffer 32 | unsigned int readMessage(uint8_t *buffer, unsigned int size); 33 | // Receive a message and store it inside a String 34 | void readMessage(String &str, unsigned int maxLength = 128); 35 | 36 | // Send a message 37 | void writeMessage(const uint8_t *buffer, unsigned int size); 38 | // Send a message 39 | void writeMessage(const String& str); 40 | // Send a JSON message 41 | void writeJSON(const String& str); 42 | 43 | // Return the size of the next available message, 0 if there are 44 | // no messages in queue. 45 | unsigned int messageAvailable(); 46 | 47 | private: 48 | BridgeClass &bridge; 49 | }; 50 | 51 | extern MailboxClass Mailbox; 52 | 53 | #endif // _MAILBOX_CLASS_H_INCLUDED_ 54 | -------------------------------------------------------------------------------- /libraries/Bridge/src/Process.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 Arduino LLC. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef PROCESS_H_ 20 | #define PROCESS_H_ 21 | 22 | #include "Arduino.h" 23 | #include 24 | #include 25 | 26 | typedef union { 27 | int pipes[2]; 28 | struct { 29 | int read; 30 | int write; 31 | }; 32 | } pipe_t; 33 | 34 | typedef struct { 35 | pipe_t in; 36 | pipe_t out; 37 | pipe_t err; 38 | } process_pipes_t; 39 | 40 | class Process : public Stream { 41 | private: 42 | boolean success; 43 | boolean executed; 44 | StringArray cmd_array; 45 | int exec_pid; 46 | int exec_result; 47 | process_pipes_t pipes; 48 | pthread_t thread; 49 | boolean thread_running; 50 | 51 | public: 52 | // Constructor with a user provided BridgeClass instance 53 | Process(BridgeClass &_b = Bridge); 54 | ~Process(); 55 | operator bool () { return success; } 56 | 57 | void begin(const String &command); 58 | void addParameter(const String ¶m); 59 | void close(); 60 | 61 | void runAsynchronously(); 62 | boolean running(); 63 | unsigned int exitValue(){ return exec_result; } 64 | 65 | // Stream methods 66 | // (read from process stdout) 67 | int available(); 68 | int read(); 69 | int read(char * buf, size_t len); 70 | int peek(){ return -1; } 71 | // (write to process stdin) 72 | size_t write(uint8_t); 73 | size_t write(uint8_t *data, size_t len); 74 | void flush(){} 75 | // (read from process stderr) 76 | int errAvailable(); 77 | int errRead(); 78 | int errRead(char * buf, size_t len); 79 | 80 | unsigned int run(); 81 | unsigned int runShellCommand(const String &command); 82 | void runShellCommandAsynchronously(const String &command); 83 | 84 | //called by the created thread 85 | //will block if called directly 86 | //and will execute on the same thread 87 | void execute(); 88 | }; 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /libraries/Bridge/src/YunClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 Arduino LLC. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _YUN_CLIENT_H_ 20 | #define _YUN_CLIENT_H_ 21 | 22 | #include 23 | 24 | #warning "The use of YunClient is deprecated. Use BridgeClient instead!" 25 | typedef BridgeClient YunClient; 26 | 27 | #endif // _YUN_CLIENT_H_ 28 | -------------------------------------------------------------------------------- /libraries/Bridge/src/YunServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 Arduino LLC. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _YUN_SERVER_H_ 20 | #define _YUN_SERVER_H_ 21 | 22 | #include 23 | 24 | #warning "The use of YunServer is deprecated. Use BridgeServer instead!" 25 | typedef BridgeServer YunServer; 26 | 27 | #endif // _YUN_SERVER_H_ 28 | -------------------------------------------------------------------------------- /libraries/DHT22/DHT22.h: -------------------------------------------------------------------------------- 1 | #ifndef _DHT22_H_ 2 | #define _DHT22_H_ 3 | 4 | #include 5 | 6 | #define DHT22_ERROR_VALUE -995 7 | 8 | typedef enum{ 9 | DHT_ERROR_NONE = 0, 10 | DHT_BUS_HUNG, 11 | DHT_ERROR_NOT_PRESENT, 12 | DHT_ERROR_ACK_TOO_LONG1, 13 | DHT_ERROR_ACK_TOO_LONG2, 14 | DHT_ERROR_ACK_TOO_LONG3, 15 | DHT_ERROR_SYNC_TIMEOUT, 16 | DHT_ERROR_DATA_TIMEOUT, 17 | DHT_ERROR_CHECKSUM, 18 | DHT_ERROR_TOOQUICK 19 | } DHT22_ERROR_t; 20 | 21 | class DHT22{ 22 | private: 23 | uint8_t _bitmask; 24 | unsigned long _lastReadTime; 25 | short int _lastHumidity; 26 | short int _lastTemperature; 27 | 28 | public: 29 | DHT22(uint8_t pin); 30 | DHT22_ERROR_t readData(); 31 | short int getHumidityInt(); 32 | short int getTemperatureCInt(); 33 | float getHumidity(); 34 | float getTemperatureC(); 35 | }; 36 | 37 | // Report the humidity in .1 percent increments, such that 635 means 63.5% relative humidity 38 | inline short int DHT22::getHumidityInt(){ 39 | return _lastHumidity; 40 | } 41 | 42 | // Get the temperature in decidegrees C, such that 326 means 32.6 degrees C. 43 | // The temperature may be negative, so be careful when handling the fractional part. 44 | inline short int DHT22::getTemperatureCInt(){ 45 | return _lastTemperature; 46 | } 47 | 48 | inline float DHT22::getHumidity(){ 49 | return float(_lastHumidity)/10; 50 | } 51 | 52 | inline float DHT22::getTemperatureC(){ 53 | return float(_lastTemperature)/10; 54 | } 55 | 56 | #endif /*_DHT22_H_*/ 57 | -------------------------------------------------------------------------------- /libraries/DHT22/DHT22.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me-no-dev/RasPiArduino/29fad57fa5d42cece2d5370831ba8f2a47b373c2/libraries/DHT22/DHT22.pdf -------------------------------------------------------------------------------- /libraries/DHT22/README: -------------------------------------------------------------------------------- 1 | DHT22.cpp - DHT22 sensor library 2 | Developed by Ben Adams - 2011 3 | 4 | Humidity and Temperature Sensor DHT22 info found at 5 | http://www.sparkfun.com/products/10167 6 | The same sensor has also been spotted going by the names RHT22, AM2302 7 | and RHT03 from a variety of vendors. It uses a non-standard 1-wire digital 8 | signalling protocol. 9 | 10 | To install this library for use with the Arduino IDE, copy it 11 | to the `libraries' folder and restart the IDE. For an example of 12 | how to use it, see File->Examples->DHT22->Serial . 13 | 14 | Version 0.5: 15-Jan-2012 by Craig Ringer 15 | Update to support Arduino 1.0 16 | Make accessors inlineable so they can be optimised away 17 | Preserve original integer values from sensor and offer access to them 18 | Permit floating point support to be disalbed by defining DHT22_NO_FLOAT before including DHT22.h 19 | 20 | Version 0.4: 24-Jan-2011 by Ben Adams 21 | Added return code constants to keywords.txt 22 | Returns DHT_ERROR_CHECKSUM on check sum mismatch 23 | 24 | Version 0.3: 17-Jan-2011 by Ben Adams 25 | This version reads data 26 | Needs check sum code added at the end of readData 27 | 28 | Version 0.2: 16-Jan-2011 by Ben Adams 29 | Changed coding style to match other Arduino libraries. 30 | This version will not read data either! 31 | 32 | Version 0.1: 10-Jan-2011 by Ben Adams nethoncho AT gmail.com 33 | First Version is a skeleton. This version will not read data! 34 | Code adapted from the following sources: 35 | The Arduino OneWire lib 36 | http://sheepdogguides.com/arduino/ar3ne1humDHT11.htm 37 | -------------------------------------------------------------------------------- /libraries/DHT22/examples/DHTConsole/DHTConsole.ino: -------------------------------------------------------------------------------- 1 | #include 2 | // Only used for sprintf 3 | #include 4 | 5 | // Data wire is plugged into port 7 on the Arduino 6 | // Connect a 4.7K resistor between VCC and the data pin (strong pullup) 7 | #define DHT22_PIN 7 8 | 9 | // Setup a DHT22 instance 10 | DHT22 myDHT22(DHT22_PIN); 11 | 12 | void setup() 13 | { 14 | Console.println("DHT22 Library Demo"); 15 | } 16 | 17 | void loop() 18 | { 19 | DHT22_ERROR_t errorCode; 20 | 21 | // The sensor can only be read from every 1-2s, and requires a minimum 22 | // 2s warm-up after power-on. 23 | delay(2000); 24 | 25 | Console.print("Requesting data..."); 26 | errorCode = myDHT22.readData(); 27 | switch(errorCode) 28 | { 29 | case DHT_ERROR_NONE: 30 | Console.print("Got Data "); 31 | Console.print(myDHT22.getTemperatureC()); 32 | Console.print("C "); 33 | Console.print(myDHT22.getHumidity()); 34 | Console.println("%"); 35 | // Alternately, with integer formatting which is clumsier but more compact to store and 36 | // can be compared reliably for equality: 37 | // 38 | char buf[128]; 39 | sprintf(buf, "Integer-only reading: Temperature %hi.%01hi C, Humidity %i.%01i %% RH", 40 | myDHT22.getTemperatureCInt()/10, abs(myDHT22.getTemperatureCInt()%10), 41 | myDHT22.getHumidityInt()/10, myDHT22.getHumidityInt()%10); 42 | Console.println(buf); 43 | break; 44 | case DHT_ERROR_CHECKSUM: 45 | Console.print("check sum error "); 46 | Console.print(myDHT22.getTemperatureC()); 47 | Console.print("C "); 48 | Console.print(myDHT22.getHumidity()); 49 | Console.println("%"); 50 | break; 51 | case DHT_BUS_HUNG: 52 | Console.println("BUS Hung "); 53 | break; 54 | case DHT_ERROR_NOT_PRESENT: 55 | Console.println("Not Present "); 56 | break; 57 | case DHT_ERROR_ACK_TOO_LONG1: 58 | case DHT_ERROR_ACK_TOO_LONG2: 59 | case DHT_ERROR_ACK_TOO_LONG3: 60 | Console.println("ACK time out "); 61 | break; 62 | case DHT_ERROR_SYNC_TIMEOUT: 63 | Console.println("Sync Timeout "); 64 | break; 65 | case DHT_ERROR_DATA_TIMEOUT: 66 | Console.println("Data Timeout "); 67 | break; 68 | case DHT_ERROR_TOOQUICK: 69 | Console.println("Polled to quick "); 70 | break; 71 | } 72 | } -------------------------------------------------------------------------------- /libraries/DHT22/examples/DHTSerial/DHTSerial.ino: -------------------------------------------------------------------------------- 1 | #include 2 | // Only used for sprintf 3 | #include 4 | 5 | // Data wire is plugged into port 7 on the Arduino 6 | // Connect a 4.7K resistor between VCC and the data pin (strong pullup) 7 | #define DHT22_PIN 7 8 | 9 | // Setup a DHT22 instance 10 | DHT22 myDHT22(DHT22_PIN); 11 | 12 | void setup() 13 | { 14 | // start serial port 15 | Serial.begin(9600); 16 | Serial.println("DHT22 Library Demo"); 17 | } 18 | 19 | void loop() 20 | { 21 | DHT22_ERROR_t errorCode; 22 | 23 | // The sensor can only be read from every 1-2s, and requires a minimum 24 | // 2s warm-up after power-on. 25 | delay(2000); 26 | 27 | Serial.print("Requesting data..."); 28 | errorCode = myDHT22.readData(); 29 | switch(errorCode) 30 | { 31 | case DHT_ERROR_NONE: 32 | Serial.print("Got Data "); 33 | Serial.print(myDHT22.getTemperatureC()); 34 | Serial.print("C "); 35 | Serial.print(myDHT22.getHumidity()); 36 | Serial.println("%"); 37 | // Alternately, with integer formatting which is clumsier but more compact to store and 38 | // can be compared reliably for equality: 39 | // 40 | char buf[128]; 41 | sprintf(buf, "Integer-only reading: Temperature %hi.%01hi C, Humidity %i.%01i %% RH", 42 | myDHT22.getTemperatureCInt()/10, abs(myDHT22.getTemperatureCInt()%10), 43 | myDHT22.getHumidityInt()/10, myDHT22.getHumidityInt()%10); 44 | Serial.println(buf); 45 | break; 46 | case DHT_ERROR_CHECKSUM: 47 | Serial.print("check sum error "); 48 | Serial.print(myDHT22.getTemperatureC()); 49 | Serial.print("C "); 50 | Serial.print(myDHT22.getHumidity()); 51 | Serial.println("%"); 52 | break; 53 | case DHT_BUS_HUNG: 54 | Serial.println("BUS Hung "); 55 | break; 56 | case DHT_ERROR_NOT_PRESENT: 57 | Serial.println("Not Present "); 58 | break; 59 | case DHT_ERROR_ACK_TOO_LONG1: 60 | case DHT_ERROR_ACK_TOO_LONG2: 61 | case DHT_ERROR_ACK_TOO_LONG3: 62 | Serial.println("ACK time out "); 63 | break; 64 | case DHT_ERROR_SYNC_TIMEOUT: 65 | Serial.println("Sync Timeout "); 66 | break; 67 | case DHT_ERROR_DATA_TIMEOUT: 68 | Serial.println("Data Timeout "); 69 | break; 70 | case DHT_ERROR_TOOQUICK: 71 | Serial.println("Polled to quick "); 72 | break; 73 | } 74 | } -------------------------------------------------------------------------------- /libraries/DHT22/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For DHT22 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | DHT22 KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | readData KEYWORD2 16 | getHumidity KEYWORD2 17 | getHumidityInt KEYWORD2 18 | getTemperatureC KEYWORD2 19 | getTemperatureCInt KEYWORD2 20 | clockReset KEYWORD2 21 | 22 | ####################################### 23 | # Instances (KEYWORD2) 24 | ####################################### 25 | 26 | 27 | ####################################### 28 | # Constants (LITERAL1) 29 | ####################################### 30 | 31 | DHT_ERROR_NONE LITERAL1 32 | DHT_BUS_HUNG LITERAL1 33 | DHT_ERROR_NOT_PRESENT LITERAL1 34 | DHT_ERROR_ACK_TOO_LONG LITERAL1 35 | DHT_ERROR_SYNC_TIMEOUT LITERAL1 36 | DHT_ERROR_DATA_TIMEOUT LITERAL1 37 | DHT_ERROR_CHECKSUM LITERAL1 38 | DHT_ERROR_TOOQUICK LITERAL1 39 | -------------------------------------------------------------------------------- /libraries/DS3231/DS3231.h: -------------------------------------------------------------------------------- 1 | /* 2 | DS3231 library for Raspberry Pi Arduino. 3 | Copyright (c) 2015 by Hristo Gochkov 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | #ifndef DS3231_h 20 | #define DS3231_h 21 | #include "Arduino.h" 22 | 23 | #define DS3231_SQW_MASK 0x18 24 | #define DS3231_SQW_1HZ 0x00 25 | #define DS3231_SQW_1KHZ 0x08 26 | #define DS3231_SQW_4KHZ 0x10 27 | #define DS3231_SQW_8KHZ 0x18 28 | 29 | //registers 30 | #define RTCDR 0x00 //data register start 31 | #define RTCA1 0x07 //Alarm1 register start 32 | #define RTCA2 0x0B //Alarm 2 register start 33 | #define RTCCR 0x0E //Control Register 34 | #define RTCSR 0x0F //Status Register 35 | #define RTCAO 0x10 //Aging Offset 36 | #define RTCTH 0x11 //Temperature MSB 37 | #define RTCTL 0x12 //Temperature LSB (value * 0.25 deg) 38 | 39 | //Control register bits 40 | #define RTCEOSC (1 << 7) //Enable Oscillator (active low) 41 | #define RTCBBSQW (1 << 6) //Battery-Backed Square-Wave Enable 42 | #define RTCCONV (1 << 5) //Convert Temperature 43 | #define RTCRS2 (1 << 4) //Rate Select 44 | #define RTCRS1 (1 << 3) //Rate Select 45 | #define RTCINTCN (1 << 2) //Interrupt Control 46 | #define RTCA2IE (1 << 1) //Alarm 2 Interrupt Enable 47 | #define RTCA1IE (1 << 0) //Alarm 1 Interrupt Enable 48 | 49 | //Status register bits 50 | #define RTCOSF (1 << 7) //Oscillator Stop Flag (clear needed) 51 | #define RTCEN32kHz (1 << 3) //Enable 32kHz Output 52 | #define RTCBSY (1 << 2) //Busy 53 | #define RTCA2F (1 << 1) //Alarm 2 Flag 54 | #define RTCA1F (1 << 0) //Alarm 1 Flag 55 | 56 | typedef struct { 57 | uint8_t s; 58 | uint8_t m; 59 | uint8_t h; 60 | uint8_t w; 61 | uint8_t d; 62 | uint8_t mo; 63 | uint8_t y; // offset from 2000; 64 | } rtc_t; 65 | 66 | class DS3231 { 67 | public: 68 | DS3231(){} 69 | ~DS3231(){} 70 | void begin(); 71 | int getReg(uint8_t address); 72 | bool setReg(uint8_t address, uint8_t value); 73 | bool updateReg(uint8_t address, uint8_t value, uint8_t mask); 74 | bool read(uint8_t address, uint8_t *data, uint16_t len); 75 | bool read(rtc_t &tm); 76 | bool write(uint8_t address, uint8_t *data, uint16_t len); 77 | bool write(rtc_t &tm); 78 | bool set(void); 79 | bool hasStopped(void); 80 | uint16_t temperature(void); 81 | 82 | bool setAlarm1(int seconds=-1, int minutes=-1, int hour=-1, int day=-1, bool weekday=false); 83 | bool enableAlarm1(void); 84 | bool disableAlarm1(void); 85 | bool hasAlarm1(void); 86 | bool isAlarm1Enabled(void); 87 | 88 | bool setAlarm2(int minutes=-1, int hour=-1, int day=-1, bool weekday=false); 89 | bool enableAlarm2(void); 90 | bool disableAlarm2(void); 91 | bool hasAlarm2(void); 92 | bool isAlarm2Enabled(void); 93 | }; 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /libraries/DS3231/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Class (KEYWORD1) 3 | ####################################### 4 | 5 | 6 | 7 | ####################################### 8 | # Methods and Functions (KEYWORD2) 9 | ####################################### 10 | 11 | 12 | 13 | ####################################### 14 | # Constants (LITERAL1) 15 | ####################################### 16 | 17 | 18 | -------------------------------------------------------------------------------- /libraries/EEPROM/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For EEPROM 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | EEPROM KEYWORD1 10 | EERef KEYWORD1 11 | EEPtr KEYWORD2 12 | 13 | ####################################### 14 | # Methods and Functions (KEYWORD2) 15 | ####################################### 16 | 17 | update KEYWORD2 18 | 19 | ####################################### 20 | # Constants (LITERAL1) 21 | ####################################### 22 | 23 | -------------------------------------------------------------------------------- /libraries/EEPROM/library.properties: -------------------------------------------------------------------------------- 1 | name=EEPROM 2 | version=2.0 3 | author=Arduino, Christopher Andrews 4 | maintainer=Arduino 5 | sentence=Enables reading and writing to the permanent board storage. For all Arduino boards BUT Arduino DUE and Arduino ZERO. 6 | paragraph= 7 | category=Data Storage 8 | url=http://www.arduino.cc/en/Reference/EEPROM 9 | architectures=* 10 | 11 | -------------------------------------------------------------------------------- /libraries/Ethernet/README.adoc: -------------------------------------------------------------------------------- 1 | = Ethernet Library for Arduino = 2 | 3 | With the Arduino Ethernet Shield, this library allows an Arduino board to connect to the internet. 4 | 5 | For more information about this library please visit us at 6 | http://www.arduino.cc/en/Reference/Ethernet 7 | 8 | == License == 9 | 10 | Copyright (c) 2010 Arduino LLC. All right reserved. 11 | 12 | This library is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | 17 | This library is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | Lesser General Public License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with this library; if not, write to the Free Software 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | -------------------------------------------------------------------------------- /libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Advanced Chat Server 3 | 4 | A more advanced server that distributes any incoming messages 5 | to all connected clients but the client the message comes from. 6 | To use, telnet to your device's IP address and type. 7 | You can see the client's input in the serial monitor as well. 8 | Using an Arduino Wiznet Ethernet shield. 9 | 10 | Circuit: 11 | * Ethernet shield attached to pins 10, 11, 12, 13 12 | 13 | created 18 Dec 2009 14 | by David A. Mellis 15 | modified 9 Apr 2012 16 | by Tom Igoe 17 | redesigned to make use of operator== 25 Nov 2013 18 | by Norbert Truchsess 19 | 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | // Enter a MAC address and IP address for your controller below. 26 | // The IP address will be dependent on your local network. 27 | // gateway and subnet are optional: 28 | byte mac[] = { 29 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED 30 | }; 31 | IPAddress ip(192, 168, 1, 177); 32 | IPAddress myDns(192, 168, 1, 1); 33 | IPAddress gateway(192, 168, 1, 1); 34 | IPAddress subnet(255, 255, 0, 0); 35 | 36 | 37 | // telnet defaults to port 23 38 | EthernetServer server(23); 39 | 40 | EthernetClient clients[4]; 41 | 42 | void setup() { 43 | // initialize the Ethernet device 44 | Ethernet.begin(mac, ip, myDns, gateway, subnet); 45 | // start listening for clients 46 | server.begin(); 47 | // Open serial communications and wait for port to open: 48 | Serial.begin(9600); 49 | while (!Serial) { 50 | ; // wait for serial port to connect. Needed for native USB port only 51 | } 52 | 53 | 54 | Serial.print("Chat server address:"); 55 | Serial.println(Ethernet.localIP()); 56 | } 57 | 58 | void loop() { 59 | // wait for a new client: 60 | EthernetClient client = server.available(); 61 | 62 | // when the client sends the first byte, say hello: 63 | if (client) { 64 | 65 | boolean newClient = true; 66 | for (byte i = 0; i < 4; i++) { 67 | //check whether this client refers to the same socket as one of the existing instances: 68 | if (clients[i] == client) { 69 | newClient = false; 70 | break; 71 | } 72 | } 73 | 74 | if (newClient) { 75 | //check which of the existing clients can be overridden: 76 | for (byte i = 0; i < 4; i++) { 77 | if (!clients[i] && clients[i] != client) { 78 | clients[i] = client; 79 | // clear out the input buffer: 80 | client.flush(); 81 | Serial.println("We have a new client"); 82 | client.print("Hello, client number: "); 83 | client.print(i); 84 | client.println(); 85 | break; 86 | } 87 | } 88 | } 89 | 90 | if (client.available() > 0) { 91 | // read the bytes incoming from the client: 92 | char thisChar = client.read(); 93 | // echo the bytes back to all other connected clients: 94 | for (byte i = 0; i < 4; i++) { 95 | if (clients[i] && (clients[i] != client)) { 96 | clients[i].write(thisChar); 97 | } 98 | } 99 | // echo the bytes to the server as well: 100 | Serial.write(thisChar); 101 | } 102 | } 103 | for (byte i = 0; i < 4; i++) { 104 | if (!(clients[i].connected())) { 105 | // client.stop() invalidates the internal socket-descriptor, so next use of == will allways return false; 106 | clients[i].stop(); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /libraries/Ethernet/examples/ChatServer/ChatServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Chat Server 3 | 4 | A simple server that distributes any incoming messages to all 5 | connected clients. To use, telnet to your device's IP address and type. 6 | You can see the client's input in the serial monitor as well. 7 | Using an Arduino Wiznet Ethernet shield. 8 | 9 | Circuit: 10 | * Ethernet shield attached to pins 10, 11, 12, 13 11 | 12 | created 18 Dec 2009 13 | by David A. Mellis 14 | modified 9 Apr 2012 15 | by Tom Igoe 16 | 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | // Enter a MAC address and IP address for your controller below. 23 | // The IP address will be dependent on your local network. 24 | // gateway and subnet are optional: 25 | byte mac[] = { 26 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED 27 | }; 28 | IPAddress ip(192, 168, 1, 177); 29 | IPAddress myDns(192,168,1, 1); 30 | IPAddress gateway(192, 168, 1, 1); 31 | IPAddress subnet(255, 255, 0, 0); 32 | 33 | 34 | // telnet defaults to port 23 35 | EthernetServer server(23); 36 | boolean alreadyConnected = false; // whether or not the client was connected previously 37 | 38 | void setup() { 39 | // initialize the ethernet device 40 | Ethernet.begin(mac, ip, myDns, gateway, subnet); 41 | // start listening for clients 42 | server.begin(); 43 | // Open serial communications and wait for port to open: 44 | Serial.begin(9600); 45 | while (!Serial) { 46 | ; // wait for serial port to connect. Needed for native USB port only 47 | } 48 | 49 | 50 | Serial.print("Chat server address:"); 51 | Serial.println(Ethernet.localIP()); 52 | } 53 | 54 | void loop() { 55 | // wait for a new client: 56 | EthernetClient client = server.available(); 57 | 58 | // when the client sends the first byte, say hello: 59 | if (client) { 60 | if (!alreadyConnected) { 61 | // clear out the input buffer: 62 | client.flush(); 63 | Serial.println("We have a new client"); 64 | client.println("Hello, client!"); 65 | alreadyConnected = true; 66 | } 67 | 68 | if (client.available() > 0) { 69 | // read the bytes incoming from the client: 70 | char thisChar = client.read(); 71 | // echo the bytes back to the client: 72 | server.write(thisChar); 73 | // echo the bytes to the server as well: 74 | Serial.write(thisChar); 75 | } 76 | } 77 | } 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino: -------------------------------------------------------------------------------- 1 | /* 2 | DHCP-based IP printer 3 | 4 | This sketch uses the DHCP extensions to the Ethernet library 5 | to get an IP address via DHCP and print the address obtained. 6 | using an Arduino Wiznet Ethernet shield. 7 | 8 | Circuit: 9 | Ethernet shield attached to pins 10, 11, 12, 13 10 | 11 | created 12 April 2011 12 | modified 9 Apr 2012 13 | by Tom Igoe 14 | modified 02 Sept 2015 15 | by Arturo Guadalupi 16 | 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | // Enter a MAC address for your controller below. 23 | // Newer Ethernet shields have a MAC address printed on a sticker on the shield 24 | byte mac[] = { 25 | 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 26 | }; 27 | 28 | // Initialize the Ethernet client library 29 | // with the IP address and port of the server 30 | // that you want to connect to (port 80 is default for HTTP): 31 | EthernetClient client; 32 | 33 | void setup() { 34 | // Open serial communications and wait for port to open: 35 | Serial.begin(9600); 36 | // this check is only needed on the Leonardo: 37 | while (!Serial) { 38 | ; // wait for serial port to connect. Needed for native USB port only 39 | } 40 | 41 | // start the Ethernet connection: 42 | if (Ethernet.begin(mac) == 0) { 43 | Serial.println("Failed to configure Ethernet using DHCP"); 44 | // no point in carrying on, so do nothing forevermore: 45 | for (;;) 46 | ; 47 | } 48 | // print your local IP address: 49 | printIPAddress(); 50 | } 51 | 52 | void loop() { 53 | 54 | switch (Ethernet.maintain()) 55 | { 56 | case 1: 57 | //renewed fail 58 | Serial.println("Error: renewed fail"); 59 | break; 60 | 61 | case 2: 62 | //renewed success 63 | Serial.println("Renewed success"); 64 | 65 | //print your local IP address: 66 | printIPAddress(); 67 | break; 68 | 69 | case 3: 70 | //rebind fail 71 | Serial.println("Error: rebind fail"); 72 | break; 73 | 74 | case 4: 75 | //rebind success 76 | Serial.println("Rebind success"); 77 | 78 | //print your local IP address: 79 | printIPAddress(); 80 | break; 81 | 82 | default: 83 | //nothing happened 84 | break; 85 | 86 | } 87 | } 88 | 89 | void printIPAddress() 90 | { 91 | Serial.print("My IP address: "); 92 | for (byte thisByte = 0; thisByte < 4; thisByte++) { 93 | // print the value of each byte of the IP address: 94 | Serial.print(Ethernet.localIP()[thisByte], DEC); 95 | Serial.print("."); 96 | } 97 | 98 | Serial.println(); 99 | } 100 | -------------------------------------------------------------------------------- /libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | DHCP Chat Server 3 | 4 | A simple server that distributes any incoming messages to all 5 | connected clients. To use, telnet to your device's IP address and type. 6 | You can see the client's input in the serial monitor as well. 7 | Using an Arduino Wiznet Ethernet shield. 8 | 9 | THis version attempts to get an IP address using DHCP 10 | 11 | Circuit: 12 | * Ethernet shield attached to pins 10, 11, 12, 13 13 | 14 | created 21 May 2011 15 | modified 9 Apr 2012 16 | by Tom Igoe 17 | modified 02 Sept 2015 18 | by Arturo Guadalupi 19 | Based on ChatServer example by David A. Mellis 20 | 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | // Enter a MAC address and IP address for your controller below. 27 | // The IP address will be dependent on your local network. 28 | // gateway and subnet are optional: 29 | byte mac[] = { 30 | 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 31 | }; 32 | IPAddress ip(192, 168, 1, 177); 33 | IPAddress myDns(192,168,1, 1); 34 | IPAddress gateway(192, 168, 1, 1); 35 | IPAddress subnet(255, 255, 0, 0); 36 | 37 | // telnet defaults to port 23 38 | EthernetServer server(23); 39 | boolean gotAMessage = false; // whether or not you got a message from the client yet 40 | 41 | void setup() { 42 | // Open serial communications and wait for port to open: 43 | Serial.begin(9600); 44 | // this check is only needed on the Leonardo: 45 | while (!Serial) { 46 | ; // wait for serial port to connect. Needed for native USB port only 47 | } 48 | 49 | 50 | // start the Ethernet connection: 51 | Serial.println("Trying to get an IP address using DHCP"); 52 | if (Ethernet.begin(mac) == 0) { 53 | Serial.println("Failed to configure Ethernet using DHCP"); 54 | // initialize the Ethernet device not using DHCP: 55 | Ethernet.begin(mac, ip, myDns, gateway, subnet); 56 | } 57 | // print your local IP address: 58 | Serial.print("My IP address: "); 59 | ip = Ethernet.localIP(); 60 | for (byte thisByte = 0; thisByte < 4; thisByte++) { 61 | // print the value of each byte of the IP address: 62 | Serial.print(ip[thisByte], DEC); 63 | Serial.print("."); 64 | } 65 | Serial.println(); 66 | // start listening for clients 67 | server.begin(); 68 | 69 | } 70 | 71 | void loop() { 72 | // wait for a new client: 73 | EthernetClient client = server.available(); 74 | 75 | // when the client sends the first byte, say hello: 76 | if (client) { 77 | if (!gotAMessage) { 78 | Serial.println("We have a new client"); 79 | client.println("Hello, client!"); 80 | gotAMessage = true; 81 | } 82 | 83 | // read the bytes incoming from the client: 84 | char thisChar = client.read(); 85 | // echo the bytes back to the client: 86 | server.write(thisChar); 87 | // echo the bytes to the server as well: 88 | Serial.print(thisChar); 89 | Ethernet.maintain(); 90 | } 91 | } 92 | 93 | -------------------------------------------------------------------------------- /libraries/Ethernet/examples/TelnetClient/TelnetClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Telnet client 3 | 4 | This sketch connects to a a telnet server (http://www.google.com) 5 | using an Arduino Wiznet Ethernet shield. You'll need a telnet server 6 | to test this with. 7 | Processing's ChatServer example (part of the network library) works well, 8 | running on port 10002. It can be found as part of the examples 9 | in the Processing application, available at 10 | http://processing.org/ 11 | 12 | Circuit: 13 | * Ethernet shield attached to pins 10, 11, 12, 13 14 | 15 | created 14 Sep 2010 16 | modified 9 Apr 2012 17 | by Tom Igoe 18 | 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | // Enter a MAC address and IP address for your controller below. 25 | // The IP address will be dependent on your local network: 26 | byte mac[] = { 27 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED 28 | }; 29 | IPAddress ip(192, 168, 1, 177); 30 | 31 | // Enter the IP address of the server you're connecting to: 32 | IPAddress server(1, 1, 1, 1); 33 | 34 | // Initialize the Ethernet client library 35 | // with the IP address and port of the server 36 | // that you want to connect to (port 23 is default for telnet; 37 | // if you're using Processing's ChatServer, use port 10002): 38 | EthernetClient client; 39 | 40 | void setup() { 41 | // start the Ethernet connection: 42 | Ethernet.begin(mac, ip); 43 | // Open serial communications and wait for port to open: 44 | Serial.begin(9600); 45 | while (!Serial) { 46 | ; // wait for serial port to connect. Needed for native USB port only 47 | } 48 | 49 | 50 | // give the Ethernet shield a second to initialize: 51 | delay(1000); 52 | Serial.println("connecting..."); 53 | 54 | // if you get a connection, report back via serial: 55 | if (client.connect(server, 10002)) { 56 | Serial.println("connected"); 57 | } else { 58 | // if you didn't get a connection to the server: 59 | Serial.println("connection failed"); 60 | } 61 | } 62 | 63 | void loop() { 64 | // if there are incoming bytes available 65 | // from the server, read them and print them: 66 | if (client.available()) { 67 | char c = client.read(); 68 | Serial.print(c); 69 | } 70 | 71 | // as long as there are bytes in the serial queue, 72 | // read them and send them out the socket if it's open: 73 | while (Serial.available() > 0) { 74 | char inChar = Serial.read(); 75 | if (client.connected()) { 76 | client.print(inChar); 77 | } 78 | } 79 | 80 | // if the server's disconnected, stop the client: 81 | if (!client.connected()) { 82 | Serial.println(); 83 | Serial.println("disconnecting."); 84 | client.stop(); 85 | // do nothing: 86 | while (true); 87 | } 88 | } 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino: -------------------------------------------------------------------------------- 1 | /* 2 | UDPSendReceiveString: 3 | This sketch receives UDP message strings, prints them to the serial port 4 | and sends an "acknowledge" string back to the sender 5 | 6 | A Processing sketch is included at the end of file that can be used to send 7 | and received messages for testing with a computer. 8 | 9 | created 21 Aug 2010 10 | by Michael Margolis 11 | 12 | This code is in the public domain. 13 | */ 14 | 15 | 16 | #include // needed for Arduino versions later than 0018 17 | #include 18 | #include // UDP library from: bjoern@cs.stanford.edu 12/30/2008 19 | 20 | 21 | // Enter a MAC address and IP address for your controller below. 22 | // The IP address will be dependent on your local network: 23 | byte mac[] = { 24 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED 25 | }; 26 | IPAddress ip(192, 168, 1, 177); 27 | 28 | unsigned int localPort = 8888; // local port to listen on 29 | 30 | // buffers for receiving and sending data 31 | char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet, 32 | char ReplyBuffer[] = "acknowledged"; // a string to send back 33 | 34 | // An EthernetUDP instance to let us send and receive packets over UDP 35 | EthernetUDP Udp; 36 | 37 | void setup() { 38 | // start the Ethernet and UDP: 39 | Ethernet.begin(mac, ip); 40 | Udp.begin(localPort); 41 | 42 | Serial.begin(9600); 43 | } 44 | 45 | void loop() { 46 | // if there's data available, read a packet 47 | int packetSize = Udp.parsePacket(); 48 | if (packetSize) { 49 | Serial.print("Received packet of size "); 50 | Serial.println(packetSize); 51 | Serial.print("From "); 52 | IPAddress remote = Udp.remoteIP(); 53 | for (int i = 0; i < 4; i++) { 54 | Serial.print(remote[i], DEC); 55 | if (i < 3) { 56 | Serial.print("."); 57 | } 58 | } 59 | Serial.print(", port "); 60 | Serial.println(Udp.remotePort()); 61 | 62 | // read the packet into packetBufffer 63 | Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE); 64 | Serial.println("Contents:"); 65 | Serial.println(packetBuffer); 66 | 67 | // send a reply to the IP address and port that sent us the packet we received 68 | Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); 69 | Udp.write(ReplyBuffer); 70 | Udp.endPacket(); 71 | } 72 | delay(10); 73 | } 74 | 75 | 76 | /* 77 | Processing sketch to run with this example 78 | ===================================================== 79 | 80 | // Processing UDP example to send and receive string data from Arduino 81 | // press any key to send the "Hello Arduino" message 82 | 83 | 84 | import hypermedia.net.*; 85 | 86 | UDP udp; // define the UDP object 87 | 88 | 89 | void setup() { 90 | udp = new UDP( this, 6000 ); // create a new datagram connection on port 6000 91 | //udp.log( true ); // <-- printout the connection activity 92 | udp.listen( true ); // and wait for incoming message 93 | } 94 | 95 | void draw() 96 | { 97 | } 98 | 99 | void keyPressed() { 100 | String ip = "192.168.1.177"; // the remote IP address 101 | int port = 8888; // the destination port 102 | 103 | udp.send("Hello World", ip, port ); // the message to send 104 | 105 | } 106 | 107 | void receive( byte[] data ) { // <-- default handler 108 | //void receive( byte[] data, String ip, int port ) { // <-- extended handler 109 | 110 | for(int i=0; i < data.length; i++) 111 | print(char(data[i])); 112 | println(); 113 | } 114 | */ 115 | 116 | 117 | -------------------------------------------------------------------------------- /libraries/Ethernet/examples/WebClient/WebClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Web client 3 | 4 | This sketch connects to a website (http://www.google.com) 5 | using an Arduino Wiznet Ethernet shield. 6 | 7 | Circuit: 8 | * Ethernet shield attached to pins 10, 11, 12, 13 9 | 10 | created 18 Dec 2009 11 | by David A. Mellis 12 | modified 9 Apr 2012 13 | by Tom Igoe, based on work by Adrian McEwen 14 | 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | // Enter a MAC address for your controller below. 21 | // Newer Ethernet shields have a MAC address printed on a sticker on the shield 22 | byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 23 | // if you don't want to use DNS (and reduce your sketch size) 24 | // use the numeric IP instead of the name for the server: 25 | //IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) 26 | char server[] = "www.google.com"; // name address for Google (using DNS) 27 | 28 | // Set the static IP address to use if the DHCP fails to assign 29 | IPAddress ip(192, 168, 0, 177); 30 | 31 | // Initialize the Ethernet client library 32 | // with the IP address and port of the server 33 | // that you want to connect to (port 80 is default for HTTP): 34 | EthernetClient client; 35 | 36 | void setup() { 37 | // Open serial communications and wait for port to open: 38 | Serial.begin(9600); 39 | while (!Serial) { 40 | ; // wait for serial port to connect. Needed for native USB port only 41 | } 42 | 43 | // start the Ethernet connection: 44 | if (Ethernet.begin(mac) == 0) { 45 | Serial.println("Failed to configure Ethernet using DHCP"); 46 | // try to congifure using IP address instead of DHCP: 47 | Ethernet.begin(mac, ip); 48 | } 49 | // give the Ethernet shield a second to initialize: 50 | delay(1000); 51 | Serial.println("connecting..."); 52 | 53 | // if you get a connection, report back via serial: 54 | if (client.connect(server, 80)) { 55 | Serial.println("connected"); 56 | // Make a HTTP request: 57 | client.println("GET /search?q=arduino HTTP/1.1"); 58 | client.println("Host: www.google.com"); 59 | client.println("Connection: close"); 60 | client.println(); 61 | } else { 62 | // if you didn't get a connection to the server: 63 | Serial.println("connection failed"); 64 | } 65 | } 66 | 67 | void loop() { 68 | // if there are incoming bytes available 69 | // from the server, read them and print them: 70 | if (client.available()) { 71 | char c = client.read(); 72 | Serial.print(c); 73 | } 74 | 75 | // if the server's disconnected, stop the client: 76 | if (!client.connected()) { 77 | Serial.println(); 78 | Serial.println("disconnecting."); 79 | client.stop(); 80 | 81 | // do nothing forevermore: 82 | while (true); 83 | } 84 | } 85 | 86 | -------------------------------------------------------------------------------- /libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Repeating Web client 3 | 4 | This sketch connects to a a web server and makes a request 5 | using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or 6 | the Adafruit Ethernet shield, either one will work, as long as it's got 7 | a Wiznet Ethernet module on board. 8 | 9 | This example uses DNS, by assigning the Ethernet client with a MAC address, 10 | IP address, and DNS address. 11 | 12 | Circuit: 13 | * Ethernet shield attached to pins 10, 11, 12, 13 14 | 15 | created 19 Apr 2012 16 | by Tom Igoe 17 | modified 21 Jan 2014 18 | by Federico Vanzati 19 | 20 | http://www.arduino.cc/en/Tutorial/WebClientRepeating 21 | This code is in the public domain. 22 | 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | // assign a MAC address for the ethernet controller. 29 | // fill in your address here: 30 | byte mac[] = { 31 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED 32 | }; 33 | // fill in an available IP address on your network here, 34 | // for manual configuration: 35 | IPAddress ip(192, 168, 1, 177); 36 | 37 | // fill in your Domain Name Server address here: 38 | IPAddress myDns(1, 1, 1, 1); 39 | 40 | // initialize the library instance: 41 | EthernetClient client; 42 | 43 | char server[] = "www.arduino.cc"; 44 | //IPAddress server(64,131,82,241); 45 | 46 | unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds 47 | const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds 48 | // the "L" is needed to use long type numbers 49 | 50 | void setup() { 51 | // start serial port: 52 | Serial.begin(9600); 53 | while (!Serial) { 54 | ; // wait for serial port to connect. Needed for native USB port only 55 | } 56 | 57 | // give the ethernet module time to boot up: 58 | delay(1000); 59 | // start the Ethernet connection using a fixed IP address and DNS server: 60 | Ethernet.begin(mac, ip, myDns); 61 | // print the Ethernet board/shield's IP address: 62 | Serial.print("My IP address: "); 63 | Serial.println(Ethernet.localIP()); 64 | } 65 | 66 | void loop() { 67 | // if there's incoming data from the net connection. 68 | // send it out the serial port. This is for debugging 69 | // purposes only: 70 | if (client.available()) { 71 | char c = client.read(); 72 | Serial.write(c); 73 | } 74 | 75 | // if ten seconds have passed since your last connection, 76 | // then connect again and send data: 77 | if (millis() - lastConnectionTime > postingInterval) { 78 | httpRequest(); 79 | } 80 | 81 | } 82 | 83 | // this method makes a HTTP connection to the server: 84 | void httpRequest() { 85 | // close any connection before send a new request. 86 | // This will free the socket on the WiFi shield 87 | client.stop(); 88 | 89 | // if there's a successful connection: 90 | if (client.connect(server, 80)) { 91 | Serial.println("connecting..."); 92 | // send the HTTP PUT request: 93 | client.println("GET /latest.txt HTTP/1.1"); 94 | client.println("Host: www.arduino.cc"); 95 | client.println("User-Agent: arduino-ethernet"); 96 | client.println("Connection: close"); 97 | client.println(); 98 | 99 | // note the time that the connection was made: 100 | lastConnectionTime = millis(); 101 | } else { 102 | // if you couldn't make a connection: 103 | Serial.println("connection failed"); 104 | } 105 | } 106 | 107 | 108 | -------------------------------------------------------------------------------- /libraries/Ethernet/examples/WebServer/WebServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Web Server 3 | 4 | A simple web server that shows the value of the analog input pins. 5 | using an Arduino Wiznet Ethernet shield. 6 | 7 | Circuit: 8 | * Ethernet shield attached to pins 10, 11, 12, 13 9 | * Analog inputs attached to pins A0 through A5 (optional) 10 | 11 | created 18 Dec 2009 12 | by David A. Mellis 13 | modified 9 Apr 2012 14 | by Tom Igoe 15 | modified 02 Sept 2015 16 | by Arturo Guadalupi 17 | 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | // Enter a MAC address and IP address for your controller below. 24 | // The IP address will be dependent on your local network: 25 | byte mac[] = { 26 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED 27 | }; 28 | IPAddress ip(192, 168, 1, 177); 29 | 30 | // Initialize the Ethernet server library 31 | // with the IP address and port you want to use 32 | // (port 80 is default for HTTP): 33 | EthernetServer server(80); 34 | 35 | void setup() { 36 | // Open serial communications and wait for port to open: 37 | Serial.begin(9600); 38 | while (!Serial) { 39 | ; // wait for serial port to connect. Needed for native USB port only 40 | } 41 | 42 | 43 | // start the Ethernet connection and the server: 44 | Ethernet.begin(mac, ip); 45 | server.begin(); 46 | Serial.print("server is at "); 47 | Serial.println(Ethernet.localIP()); 48 | } 49 | 50 | 51 | void loop() { 52 | // listen for incoming clients 53 | EthernetClient client = server.available(); 54 | if (client) { 55 | Serial.println("new client"); 56 | // an http request ends with a blank line 57 | boolean currentLineIsBlank = true; 58 | while (client.connected()) { 59 | if (client.available()) { 60 | char c = client.read(); 61 | Serial.write(c); 62 | // if you've gotten to the end of the line (received a newline 63 | // character) and the line is blank, the http request has ended, 64 | // so you can send a reply 65 | if (c == '\n' && currentLineIsBlank) { 66 | // send a standard http response header 67 | client.println("HTTP/1.1 200 OK"); 68 | client.println("Content-Type: text/html"); 69 | client.println("Connection: close"); // the connection will be closed after completion of the response 70 | client.println("Refresh: 5"); // refresh the page automatically every 5 sec 71 | client.println(); 72 | client.println(""); 73 | client.println(""); 74 | // output the value of each analog input pin 75 | for (int analogChannel = 0; analogChannel < 6; analogChannel++) { 76 | int sensorReading = analogRead(analogChannel); 77 | client.print("analog input "); 78 | client.print(analogChannel); 79 | client.print(" is "); 80 | client.print(sensorReading); 81 | client.println("
"); 82 | } 83 | client.println(""); 84 | break; 85 | } 86 | if (c == '\n') { 87 | // you're starting a new line 88 | currentLineIsBlank = true; 89 | } else if (c != '\r') { 90 | // you've gotten a character on the current line 91 | currentLineIsBlank = false; 92 | } 93 | } 94 | } 95 | // give the web browser time to receive the data 96 | delay(1); 97 | // close the connection: 98 | client.stop(); 99 | Serial.println("client disconnected"); 100 | Ethernet.maintain(); 101 | } 102 | } 103 | 104 | -------------------------------------------------------------------------------- /libraries/Ethernet/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Ethernet 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | Ethernet KEYWORD1 Ethernet 10 | EthernetClient KEYWORD1 EthernetClient 11 | EthernetServer KEYWORD1 EthernetServer 12 | IPAddress KEYWORD1 EthernetIPAddress 13 | 14 | ####################################### 15 | # Methods and Functions (KEYWORD2) 16 | ####################################### 17 | 18 | status KEYWORD2 19 | connect KEYWORD2 20 | write KEYWORD2 21 | available KEYWORD2 22 | read KEYWORD2 23 | peek KEYWORD2 24 | flush KEYWORD2 25 | stop KEYWORD2 26 | connected KEYWORD2 27 | begin KEYWORD2 28 | beginPacket KEYWORD2 29 | endPacket KEYWORD2 30 | parsePacket KEYWORD2 31 | remoteIP KEYWORD2 32 | remotePort KEYWORD2 33 | getSocketNumber KEYWORD2 34 | localIP KEYWORD2 35 | maintain KEYWORD2 36 | 37 | ####################################### 38 | # Constants (LITERAL1) 39 | ####################################### 40 | 41 | -------------------------------------------------------------------------------- /libraries/Ethernet/library.properties: -------------------------------------------------------------------------------- 1 | name=Ethernet 2 | version=1.1.1 3 | author=Arduino 4 | maintainer=Arduino 5 | sentence=Enables network connection (local and Internet) using the Arduino Ethernet board or shield. For all Arduino boards. 6 | paragraph=With this library you can use the Arduino Ethernet (shield or board) to connect to Internet. The library provides both Client and server functionalities. The library permits you to connect to a local network also with DHCP and to resolve DNS. 7 | category=Communication 8 | url=http://www.arduino.cc/en/Reference/Ethernet 9 | architectures=* 10 | -------------------------------------------------------------------------------- /libraries/Ethernet/src/Dns.h: -------------------------------------------------------------------------------- 1 | // Arduino DNS client for WizNet5100-based Ethernet shield 2 | // (c) Copyright 2009-2010 MCQN Ltd. 3 | // Released under Apache License, version 2.0 4 | 5 | #ifndef DNSClient_h 6 | #define DNSClient_h 7 | 8 | #include 9 | 10 | class DNSClient 11 | { 12 | public: 13 | // ctor 14 | void begin(const IPAddress& aDNSServer); 15 | 16 | /** Convert a numeric IP address string into a four-byte IP address. 17 | @param aIPAddrString IP address to convert 18 | @param aResult IPAddress structure to store the returned IP address 19 | @result 1 if aIPAddrString was successfully converted to an IP address, 20 | else error code 21 | */ 22 | int inet_aton(const char *aIPAddrString, IPAddress& aResult); 23 | 24 | /** Resolve the given hostname to an IP address. 25 | @param aHostname Name to be resolved 26 | @param aResult IPAddress structure to store the returned IP address 27 | @result 1 if aIPAddrString was successfully converted to an IP address, 28 | else error code 29 | */ 30 | int getHostByName(const char* aHostname, IPAddress& aResult); 31 | 32 | protected: 33 | uint16_t BuildRequest(const char* aName); 34 | uint16_t ProcessResponse(uint16_t aTimeout, IPAddress& aAddress); 35 | 36 | IPAddress iDNSServer; 37 | uint16_t iRequestId; 38 | EthernetUDP iUdp; 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /libraries/Ethernet/src/Ethernet.h: -------------------------------------------------------------------------------- 1 | #ifndef ethernet_h 2 | #define ethernet_h 3 | 4 | #include 5 | //#include "w5100.h" 6 | #include "IPAddress.h" 7 | #include "EthernetClient.h" 8 | #include "EthernetServer.h" 9 | #include "Dhcp.h" 10 | 11 | #define MAX_SOCK_NUM 4 12 | 13 | class EthernetClass { 14 | private: 15 | IPAddress _dnsServerAddress; 16 | DhcpClass* _dhcp; 17 | public: 18 | static uint8_t _state[MAX_SOCK_NUM]; 19 | static uint16_t _server_port[MAX_SOCK_NUM]; 20 | // Initialise the Ethernet shield to use the provided MAC address and gain the rest of the 21 | // configuration through DHCP. 22 | // Returns 0 if the DHCP configuration failed, and 1 if it succeeded 23 | int begin(uint8_t *mac_address, unsigned long timeout = 60000, unsigned long responseTimeout = 4000); 24 | void begin(uint8_t *mac_address, IPAddress local_ip); 25 | void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server); 26 | void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway); 27 | void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet); 28 | int maintain(); 29 | 30 | IPAddress localIP(); 31 | IPAddress subnetMask(); 32 | IPAddress gatewayIP(); 33 | IPAddress dnsServerIP(); 34 | 35 | friend class EthernetClient; 36 | friend class EthernetServer; 37 | }; 38 | 39 | extern EthernetClass Ethernet; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /libraries/Ethernet/src/EthernetClient.h: -------------------------------------------------------------------------------- 1 | #ifndef ethernetclient_h 2 | #define ethernetclient_h 3 | #include "Arduino.h" 4 | #include "Print.h" 5 | #include "Client.h" 6 | #include "IPAddress.h" 7 | 8 | class EthernetClient : public Client { 9 | 10 | public: 11 | EthernetClient(); 12 | EthernetClient(uint8_t sock); 13 | 14 | uint8_t status(); 15 | virtual int connect(IPAddress ip, uint16_t port); 16 | virtual int connect(const char *host, uint16_t port); 17 | virtual size_t write(uint8_t); 18 | virtual size_t write(const uint8_t *buf, size_t size); 19 | virtual int available(); 20 | virtual int read(); 21 | virtual int read(uint8_t *buf, size_t size); 22 | virtual int peek(); 23 | virtual void flush(); 24 | virtual void stop(); 25 | virtual uint8_t connected(); 26 | virtual operator bool(); 27 | virtual bool operator==(const bool value) { return bool() == value; } 28 | virtual bool operator!=(const bool value) { return bool() != value; } 29 | virtual bool operator==(const EthernetClient&); 30 | virtual bool operator!=(const EthernetClient& rhs) { return !this->operator==(rhs); }; 31 | uint8_t getSocketNumber(); 32 | 33 | friend class EthernetServer; 34 | 35 | using Print::write; 36 | 37 | private: 38 | static uint16_t _srcport; 39 | uint8_t _sock; 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /libraries/Ethernet/src/EthernetServer.cpp: -------------------------------------------------------------------------------- 1 | #include "utility/w5100.h" 2 | #include "utility/socket.h" 3 | extern "C" { 4 | #include "string.h" 5 | } 6 | 7 | #include "Ethernet.h" 8 | #include "EthernetClient.h" 9 | #include "EthernetServer.h" 10 | 11 | EthernetServer::EthernetServer(uint16_t port) 12 | { 13 | _port = port; 14 | } 15 | 16 | void EthernetServer::begin() 17 | { 18 | for (int sock = 0; sock < MAX_SOCK_NUM; sock++) { 19 | EthernetClient client(sock); 20 | if (client.status() == SnSR::CLOSED) { 21 | socket(sock, SnMR::TCP, _port, 0); 22 | listen(sock); 23 | EthernetClass::_server_port[sock] = _port; 24 | break; 25 | } 26 | } 27 | } 28 | 29 | void EthernetServer::accept() 30 | { 31 | int listening = 0; 32 | 33 | for (int sock = 0; sock < MAX_SOCK_NUM; sock++) { 34 | EthernetClient client(sock); 35 | 36 | if (EthernetClass::_server_port[sock] == _port) { 37 | if (client.status() == SnSR::LISTEN) { 38 | listening = 1; 39 | } 40 | else if (client.status() == SnSR::CLOSE_WAIT && !client.available()) { 41 | client.stop(); 42 | } 43 | } 44 | } 45 | 46 | if (!listening) { 47 | begin(); 48 | } 49 | } 50 | 51 | EthernetClient EthernetServer::available() 52 | { 53 | accept(); 54 | 55 | for (int sock = 0; sock < MAX_SOCK_NUM; sock++) { 56 | EthernetClient client(sock); 57 | if (EthernetClass::_server_port[sock] == _port) { 58 | uint8_t s = client.status(); 59 | if (s == SnSR::ESTABLISHED || s == SnSR::CLOSE_WAIT) { 60 | if (client.available()) { 61 | // XXX: don't always pick the lowest numbered socket. 62 | return client; 63 | } 64 | } 65 | } 66 | } 67 | 68 | return EthernetClient(MAX_SOCK_NUM); 69 | } 70 | 71 | size_t EthernetServer::write(uint8_t b) 72 | { 73 | return write(&b, 1); 74 | } 75 | 76 | size_t EthernetServer::write(const uint8_t *buffer, size_t size) 77 | { 78 | size_t n = 0; 79 | 80 | accept(); 81 | 82 | for (int sock = 0; sock < MAX_SOCK_NUM; sock++) { 83 | EthernetClient client(sock); 84 | 85 | if (EthernetClass::_server_port[sock] == _port && 86 | client.status() == SnSR::ESTABLISHED) { 87 | n += client.write(buffer, size); 88 | } 89 | } 90 | 91 | return n; 92 | } 93 | -------------------------------------------------------------------------------- /libraries/Ethernet/src/EthernetServer.h: -------------------------------------------------------------------------------- 1 | #ifndef ethernetserver_h 2 | #define ethernetserver_h 3 | 4 | #include "Server.h" 5 | 6 | class EthernetClient; 7 | 8 | class EthernetServer : 9 | public Server { 10 | private: 11 | uint16_t _port; 12 | void accept(); 13 | public: 14 | EthernetServer(uint16_t); 15 | EthernetClient available(); 16 | virtual void begin(); 17 | virtual size_t write(uint8_t); 18 | virtual size_t write(const uint8_t *buf, size_t size); 19 | using Print::write; 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /libraries/Ethernet/src/utility/socket.h: -------------------------------------------------------------------------------- 1 | #ifndef _SOCKET_H_ 2 | #define _SOCKET_H_ 3 | 4 | #include "utility/w5100.h" 5 | 6 | extern uint8_t socket(SOCKET s, uint8_t protocol, uint16_t port, uint8_t flag); // Opens a socket(TCP or UDP or IP_RAW mode) 7 | extern uint8_t socketStatus(SOCKET s); 8 | extern void close(SOCKET s); // Close socket 9 | extern uint8_t connect(SOCKET s, uint8_t * addr, uint16_t port); // Establish TCP connection (Active connection) 10 | extern void disconnect(SOCKET s); // disconnect the connection 11 | extern uint8_t listen(SOCKET s); // Establish TCP connection (Passive connection) 12 | extern uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len); // Send data (TCP) 13 | extern int16_t recv(SOCKET s, uint8_t * buf, int16_t len); // Receive data (TCP) 14 | extern int16_t recvAvailable(SOCKET s); 15 | extern uint16_t peek(SOCKET s, uint8_t *buf); 16 | extern uint16_t sendto(SOCKET s, const uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port); // Send data (UDP/IP RAW) 17 | extern uint16_t recvfrom(SOCKET s, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port); // Receive data (UDP/IP RAW) 18 | extern void flush(SOCKET s); // Wait for transmission to complete 19 | 20 | extern uint16_t igmpsend(SOCKET s, const uint8_t * buf, uint16_t len); 21 | 22 | // Functions to allow buffered UDP send (i.e. where the UDP datagram is built up over a 23 | // number of calls before being sent 24 | /* 25 | @brief This function sets up a UDP datagram, the data for which will be provided by one 26 | or more calls to bufferData and then finally sent with sendUDP. 27 | @return 1 if the datagram was successfully set up, or 0 if there was an error 28 | */ 29 | extern int startUDP(SOCKET s, uint8_t* addr, uint16_t port); 30 | /* 31 | @brief This function copies up to len bytes of data from buf into a UDP datagram to be 32 | sent later by sendUDP. Allows datagrams to be built up from a series of bufferData calls. 33 | @return Number of bytes successfully buffered 34 | */ 35 | uint16_t bufferData(SOCKET s, uint16_t offset, const uint8_t* buf, uint16_t len); 36 | /* 37 | @brief Send a UDP datagram built up from a sequence of startUDP followed by one or more 38 | calls to bufferData. 39 | @return 1 if the datagram was successfully sent, or 0 if there was an error 40 | */ 41 | int sendUDP(SOCKET s); 42 | 43 | #endif 44 | /* _SOCKET_H_ */ 45 | -------------------------------------------------------------------------------- /libraries/Ethernet/src/utility/util.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_H 2 | #define UTIL_H 3 | 4 | #define htons(x) ( ((x)<< 8 & 0xFF00) | \ 5 | ((x)>> 8 & 0x00FF) ) 6 | #define ntohs(x) htons(x) 7 | 8 | #define htonl(x) ( ((x)<<24 & 0xFF000000UL) | \ 9 | ((x)<< 8 & 0x00FF0000UL) | \ 10 | ((x)>> 8 & 0x0000FF00UL) | \ 11 | ((x)>>24 & 0x000000FFUL) ) 12 | #define ntohl(x) htonl(x) 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /libraries/NOKIA_LCD/NOKIA_LCD.h: -------------------------------------------------------------------------------- 1 | #ifndef NOKIA_LCD_h 2 | #define NOKIA_LCD_h 3 | 4 | #include "Arduino.h" 5 | 6 | #define CHIP_PCD8544 0 7 | #define CHIP_ST7576 1 8 | 9 | class NOKIA_LCD { 10 | public: 11 | uint8_t width; 12 | uint8_t height; 13 | 14 | NOKIA_LCD(uint8_t mosi, uint8_t sclk, uint8_t cs, uint8_t dc, uint8_t rst); 15 | 16 | void begin(uint8_t model=CHIP_PCD8544); 17 | void setPower(bool on); 18 | void setInverse(bool inverse); 19 | void stop(); 20 | void display(); 21 | void noDisplay(); 22 | 23 | void setCursor(uint8_t column, uint8_t line); 24 | void home(); 25 | void clear(); 26 | void clearLine(); 27 | 28 | void createChar(uint8_t chr, const uint8_t *glyph); // Assign a user-defined glyph (5x8) to an ASCII character (0-31)... 29 | 30 | void write(uint8_t chr); 31 | int write(const char *str); 32 | 33 | void drawBitmap(const uint8_t *data, uint8_t columns, uint8_t lines); 34 | void setPixel(uint8_t x, uint8_t y, bool value, bool write); 35 | void draw(); 36 | 37 | 38 | private: 39 | uint8_t mosiPin; 40 | uint8_t sckPin; 41 | uint8_t ssPin; 42 | uint8_t dcPin; 43 | uint8_t rstPin; 44 | 45 | uint8_t column; 46 | uint8_t line; 47 | const uint8_t *custom[32]; 48 | uint8_t lcd_buffer[504]; 49 | 50 | void init(); 51 | void send(uint8_t data); 52 | void sendData(uint8_t data); 53 | void sendCmd(uint8_t data); 54 | 55 | void writeByte(uint8_t column, uint8_t line, uint8_t data); 56 | void writeBuf(uint8_t column, uint8_t line, uint8_t *data, uint16_t len); 57 | void writeBuf(uint8_t *data); 58 | 59 | }; 60 | #endif 61 | -------------------------------------------------------------------------------- /libraries/SD/README.adoc: -------------------------------------------------------------------------------- 1 | = SD Library for Arduino = 2 | 3 | The SD library allows for reading from and writing to SD cards. 4 | 5 | For more information about this library please visit us at 6 | http://www.arduino.cc/en/Reference/SD 7 | 8 | == License == 9 | 10 | Copyright (C) 2009 by William Greiman 11 | Copyright (c) 2010 SparkFun Electronics 12 | 13 | This program is free software: you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation, either version 3 of the License, or 16 | (at your option) any later version. 17 | 18 | This program is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this program. If not, see . 25 | -------------------------------------------------------------------------------- /libraries/SD/examples/Datalogger/Datalogger.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card datalogger 3 | 4 | This example shows how to log data from three analog sensors 5 | to an SD card using the SD library. 6 | 7 | The circuit: 8 | * analog sensors on analog ins 0, 1, and 2 9 | * SD card attached to SPI bus as follows: 10 | ** MOSI - pin 11 11 | ** MISO - pin 12 12 | ** CLK - pin 13 13 | ** CS - pin 4 14 | 15 | created 24 Nov 2010 16 | modified 9 Apr 2012 17 | by Tom Igoe 18 | 19 | This example code is in the public domain. 20 | 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | const int chipSelect = 4; 27 | 28 | void setup() { 29 | // Open serial communications and wait for port to open: 30 | Serial.begin(9600); 31 | while (!Serial) { 32 | ; // wait for serial port to connect. Needed for native USB port only 33 | } 34 | 35 | 36 | Serial.print("Initializing SD card..."); 37 | 38 | // see if the card is present and can be initialized: 39 | if (!SD.begin(chipSelect)) { 40 | Serial.println("Card failed, or not present"); 41 | // don't do anything more: 42 | return; 43 | } 44 | Serial.println("card initialized."); 45 | } 46 | 47 | void loop() { 48 | // make a string for assembling the data to log: 49 | String dataString = ""; 50 | 51 | // read three sensors and append to the string: 52 | for (int analogPin = 0; analogPin < 3; analogPin++) { 53 | int sensor = analogRead(analogPin); 54 | dataString += String(sensor); 55 | if (analogPin < 2) { 56 | dataString += ","; 57 | } 58 | } 59 | 60 | // open the file. note that only one file can be open at a time, 61 | // so you have to close this one before opening another. 62 | File dataFile = SD.open("datalog.txt", FILE_WRITE); 63 | 64 | // if the file is available, write to it: 65 | if (dataFile) { 66 | dataFile.println(dataString); 67 | dataFile.close(); 68 | // print to the serial port too: 69 | Serial.println(dataString); 70 | } 71 | // if the file isn't open, pop up an error: 72 | else { 73 | Serial.println("error opening datalog.txt"); 74 | } 75 | } 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /libraries/SD/examples/DumpFile/DumpFile.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card file dump 3 | 4 | This example shows how to read a file from the SD card using the 5 | SD library and send it over the serial port. 6 | 7 | The circuit: 8 | * SD card attached to SPI bus as follows: 9 | ** MOSI - pin 11 10 | ** MISO - pin 12 11 | ** CLK - pin 13 12 | ** CS - pin 4 13 | 14 | created 22 December 2010 15 | by Limor Fried 16 | modified 9 Apr 2012 17 | by Tom Igoe 18 | 19 | This example code is in the public domain. 20 | 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | const int chipSelect = 4; 27 | 28 | void setup() { 29 | // Open serial communications and wait for port to open: 30 | Serial.begin(9600); 31 | while (!Serial) { 32 | ; // wait for serial port to connect. Needed for native USB port only 33 | } 34 | 35 | 36 | Serial.print("Initializing SD card..."); 37 | 38 | // see if the card is present and can be initialized: 39 | if (!SD.begin(chipSelect)) { 40 | Serial.println("Card failed, or not present"); 41 | // don't do anything more: 42 | return; 43 | } 44 | Serial.println("card initialized."); 45 | 46 | // open the file. note that only one file can be open at a time, 47 | // so you have to close this one before opening another. 48 | File dataFile = SD.open("datalog.txt"); 49 | 50 | // if the file is available, write to it: 51 | if (dataFile) { 52 | while (dataFile.available()) { 53 | Serial.write(dataFile.read()); 54 | } 55 | dataFile.close(); 56 | } 57 | // if the file isn't open, pop up an error: 58 | else { 59 | Serial.println("error opening datalog.txt"); 60 | } 61 | } 62 | 63 | void loop() { 64 | } 65 | 66 | -------------------------------------------------------------------------------- /libraries/SD/examples/Files/Files.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card basic file example 3 | 4 | This example shows how to create and destroy an SD card file 5 | The circuit: 6 | * SD card attached to SPI bus as follows: 7 | ** MOSI - pin 11 8 | ** MISO - pin 12 9 | ** CLK - pin 13 10 | ** CS - pin 4 11 | 12 | created Nov 2010 13 | by David A. Mellis 14 | modified 9 Apr 2012 15 | by Tom Igoe 16 | 17 | This example code is in the public domain. 18 | 19 | */ 20 | #include 21 | #include 22 | 23 | File myFile; 24 | 25 | void setup() { 26 | // Open serial communications and wait for port to open: 27 | Serial.begin(9600); 28 | while (!Serial) { 29 | ; // wait for serial port to connect. Needed for native USB port only 30 | } 31 | 32 | 33 | Serial.print("Initializing SD card..."); 34 | 35 | if (!SD.begin(4)) { 36 | Serial.println("initialization failed!"); 37 | return; 38 | } 39 | Serial.println("initialization done."); 40 | 41 | if (SD.exists("example.txt")) { 42 | Serial.println("example.txt exists."); 43 | } else { 44 | Serial.println("example.txt doesn't exist."); 45 | } 46 | 47 | // open a new file and immediately close it: 48 | Serial.println("Creating example.txt..."); 49 | myFile = SD.open("example.txt", FILE_WRITE); 50 | myFile.close(); 51 | 52 | // Check to see if the file exists: 53 | if (SD.exists("example.txt")) { 54 | Serial.println("example.txt exists."); 55 | } else { 56 | Serial.println("example.txt doesn't exist."); 57 | } 58 | 59 | // delete the file: 60 | Serial.println("Removing example.txt..."); 61 | SD.remove("example.txt"); 62 | 63 | if (SD.exists("example.txt")) { 64 | Serial.println("example.txt exists."); 65 | } else { 66 | Serial.println("example.txt doesn't exist."); 67 | } 68 | } 69 | 70 | void loop() { 71 | // nothing happens after setup finishes. 72 | } 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /libraries/SD/examples/ReadWrite/ReadWrite.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card read/write 3 | 4 | This example shows how to read and write data to and from an SD card file 5 | The circuit: 6 | * SD card attached to SPI bus as follows: 7 | ** MOSI - pin 11 8 | ** MISO - pin 12 9 | ** CLK - pin 13 10 | ** CS - pin 4 11 | 12 | created Nov 2010 13 | by David A. Mellis 14 | modified 9 Apr 2012 15 | by Tom Igoe 16 | 17 | This example code is in the public domain. 18 | 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | File myFile; 25 | 26 | void setup() { 27 | // Open serial communications and wait for port to open: 28 | Serial.begin(9600); 29 | while (!Serial) { 30 | ; // wait for serial port to connect. Needed for native USB port only 31 | } 32 | 33 | 34 | Serial.print("Initializing SD card..."); 35 | 36 | if (!SD.begin(4)) { 37 | Serial.println("initialization failed!"); 38 | return; 39 | } 40 | Serial.println("initialization done."); 41 | 42 | // open the file. note that only one file can be open at a time, 43 | // so you have to close this one before opening another. 44 | myFile = SD.open("test.txt", FILE_WRITE); 45 | 46 | // if the file opened okay, write to it: 47 | if (myFile) { 48 | Serial.print("Writing to test.txt..."); 49 | myFile.println("testing 1, 2, 3."); 50 | // close the file: 51 | myFile.close(); 52 | Serial.println("done."); 53 | } else { 54 | // if the file didn't open, print an error: 55 | Serial.println("error opening test.txt"); 56 | } 57 | 58 | // re-open the file for reading: 59 | myFile = SD.open("test.txt"); 60 | if (myFile) { 61 | Serial.println("test.txt:"); 62 | 63 | // read from the file until there's nothing else in it: 64 | while (myFile.available()) { 65 | Serial.write(myFile.read()); 66 | } 67 | // close the file: 68 | myFile.close(); 69 | } else { 70 | // if the file didn't open, print an error: 71 | Serial.println("error opening test.txt"); 72 | } 73 | } 74 | 75 | void loop() { 76 | // nothing happens after setup 77 | } 78 | 79 | 80 | -------------------------------------------------------------------------------- /libraries/SD/examples/listfiles/listfiles.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Listfiles 3 | 4 | This example shows how print out the files in a 5 | directory on a SD card 6 | 7 | The circuit: 8 | * SD card attached to SPI bus as follows: 9 | ** MOSI - pin 11 10 | ** MISO - pin 12 11 | ** CLK - pin 13 12 | ** CS - pin 4 13 | 14 | created Nov 2010 15 | by David A. Mellis 16 | modified 9 Apr 2012 17 | by Tom Igoe 18 | modified 2 Feb 2014 19 | by Scott Fitzgerald 20 | 21 | This example code is in the public domain. 22 | 23 | */ 24 | #include 25 | #include 26 | 27 | File root; 28 | 29 | void setup() { 30 | // Open serial communications and wait for port to open: 31 | Serial.begin(9600); 32 | while (!Serial) { 33 | ; // wait for serial port to connect. Needed for native USB port only 34 | } 35 | 36 | Serial.print("Initializing SD card..."); 37 | 38 | if (!SD.begin(4)) { 39 | Serial.println("initialization failed!"); 40 | return; 41 | } 42 | Serial.println("initialization done."); 43 | 44 | root = SD.open("/"); 45 | 46 | printDirectory(root, 0); 47 | 48 | Serial.println("done!"); 49 | } 50 | 51 | void loop() { 52 | // nothing happens after setup finishes. 53 | } 54 | 55 | void printDirectory(File dir, int numTabs) { 56 | while (true) { 57 | 58 | File entry = dir.openNextFile(); 59 | if (! entry) { 60 | // no more files 61 | break; 62 | } 63 | for (uint8_t i = 0; i < numTabs; i++) { 64 | Serial.print('\t'); 65 | } 66 | Serial.print(entry.name()); 67 | if (entry.isDirectory()) { 68 | Serial.println("/"); 69 | printDirectory(entry, numTabs + 1); 70 | } else { 71 | // files have sizes, directories do not 72 | Serial.print("\t\t"); 73 | Serial.println(entry.size(), DEC); 74 | } 75 | entry.close(); 76 | } 77 | } 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /libraries/SD/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map SD 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | SD KEYWORD1 SD 10 | File KEYWORD1 SD 11 | SDFile KEYWORD1 SD 12 | 13 | ####################################### 14 | # Methods and Functions (KEYWORD2) 15 | ####################################### 16 | begin KEYWORD2 17 | exists KEYWORD2 18 | mkdir KEYWORD2 19 | remove KEYWORD2 20 | rmdir KEYWORD2 21 | open KEYWORD2 22 | close KEYWORD2 23 | seek KEYWORD2 24 | position KEYWORD2 25 | size KEYWORD2 26 | 27 | ####################################### 28 | # Constants (LITERAL1) 29 | ####################################### 30 | FILE_READ LITERAL1 31 | FILE_WRITE LITERAL1 32 | -------------------------------------------------------------------------------- /libraries/SD/library.properties: -------------------------------------------------------------------------------- 1 | name=SD 2 | version=1.0.6 3 | author=Arduino, SparkFun 4 | maintainer=Arduino 5 | sentence=Enables reading and writing on SD cards. For all Arduino boards. 6 | paragraph=Once an SD memory card is connected to the SPI interfare of the Arduino board you are enabled to create files and read/write on them. You can also move through directories on the SD card. 7 | category=Data Storage 8 | url=http://www.arduino.cc/en/Reference/SD 9 | architectures=* 10 | -------------------------------------------------------------------------------- /libraries/SD/src/File.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | SD - a slightly more friendly wrapper for sdfatlib 4 | 5 | This library aims to expose a subset of SD card functionality 6 | in the form of a higher level "wrapper" object. 7 | 8 | License: GNU General Public License V3 9 | (Because sdfatlib is licensed with this.) 10 | 11 | (C) Copyright 2010 SparkFun Electronics 12 | 13 | */ 14 | 15 | #include 16 | 17 | /* for debugging file open/close leaks 18 | uint8_t nfilecount=0; 19 | */ 20 | 21 | File::File(SdFile f, const char *n) { 22 | // oh man you are kidding me, new() doesnt exist? Ok we do it by hand! 23 | _file = (SdFile *)malloc(sizeof(SdFile)); 24 | if (_file) { 25 | memcpy(_file, &f, sizeof(SdFile)); 26 | 27 | strncpy(_name, n, 12); 28 | _name[12] = 0; 29 | 30 | /* for debugging file open/close leaks 31 | nfilecount++; 32 | Serial.print("Created \""); 33 | Serial.print(n); 34 | Serial.print("\": "); 35 | Serial.println(nfilecount, DEC); 36 | */ 37 | } 38 | } 39 | 40 | File::File(void) { 41 | _file = 0; 42 | _name[0] = 0; 43 | //Serial.print("Created empty file object"); 44 | } 45 | 46 | // returns a pointer to the file name 47 | char *File::name(void) { 48 | return _name; 49 | } 50 | 51 | // a directory is a special type of file 52 | boolean File::isDirectory(void) { 53 | return (_file && _file->isDir()); 54 | } 55 | 56 | 57 | size_t File::write(uint8_t val) { 58 | return write(&val, 1); 59 | } 60 | 61 | size_t File::write(const uint8_t *buf, size_t size) { 62 | size_t t; 63 | if (!_file) { 64 | setWriteError(); 65 | return 0; 66 | } 67 | _file->clearWriteError(); 68 | t = _file->write(buf, size); 69 | if (_file->getWriteError()) { 70 | setWriteError(); 71 | return 0; 72 | } 73 | return t; 74 | } 75 | 76 | int File::peek() { 77 | if (! _file) 78 | return 0; 79 | 80 | int c = _file->read(); 81 | if (c != -1) _file->seekCur(-1); 82 | return c; 83 | } 84 | 85 | int File::read() { 86 | if (_file) 87 | return _file->read(); 88 | return -1; 89 | } 90 | 91 | // buffered read for more efficient, high speed reading 92 | int File::read(void *buf, uint16_t nbyte) { 93 | if (_file) 94 | return _file->read(buf, nbyte); 95 | return 0; 96 | } 97 | 98 | int File::available() { 99 | if (! _file) return 0; 100 | 101 | uint32_t n = size() - position(); 102 | 103 | return n > 0X7FFF ? 0X7FFF : n; 104 | } 105 | 106 | void File::flush() { 107 | if (_file) 108 | _file->sync(); 109 | } 110 | 111 | boolean File::seek(uint32_t pos) { 112 | if (! _file) return false; 113 | 114 | return _file->seekSet(pos); 115 | } 116 | 117 | uint32_t File::position() { 118 | if (! _file) return -1; 119 | return _file->curPosition(); 120 | } 121 | 122 | uint32_t File::size() { 123 | if (! _file) return 0; 124 | return _file->fileSize(); 125 | } 126 | 127 | void File::close() { 128 | if (_file) { 129 | _file->close(); 130 | free(_file); 131 | _file = 0; 132 | 133 | /* for debugging file open/close leaks 134 | nfilecount--; 135 | Serial.print("Deleted "); 136 | Serial.println(nfilecount, DEC); 137 | */ 138 | } 139 | } 140 | 141 | File::operator bool() { 142 | if (_file) 143 | return _file->isOpen(); 144 | return false; 145 | } 146 | 147 | -------------------------------------------------------------------------------- /libraries/SD/src/README.txt: -------------------------------------------------------------------------------- 1 | 2 | ** SD - a slightly more friendly wrapper for sdfatlib ** 3 | 4 | This library aims to expose a subset of SD card functionality in the 5 | form of a higher level "wrapper" object. 6 | 7 | License: GNU General Public License V3 8 | (Because sdfatlib is licensed with this.) 9 | 10 | (C) Copyright 2010 SparkFun Electronics 11 | 12 | Now better than ever with optimization, multiple file support, directory handling, etc - ladyada! 13 | 14 | -------------------------------------------------------------------------------- /libraries/SD/src/utility/SdFatUtil.h: -------------------------------------------------------------------------------- 1 | /* Arduino SdFat Library 2 | * Copyright (C) 2008 by William Greiman 3 | * 4 | * This file is part of the Arduino SdFat Library 5 | * 6 | * This Library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Arduino SdFat Library. If not, see 18 | * . 19 | */ 20 | #ifndef SdFatUtil_h 21 | #define SdFatUtil_h 22 | /** 23 | * \file 24 | * Useful utility functions. 25 | */ 26 | #include 27 | #ifdef __AVR__ 28 | #include 29 | /** Store and print a string in flash memory.*/ 30 | #define PgmPrint(x) SerialPrint_P(PSTR(x)) 31 | /** Store and print a string in flash memory followed by a CR/LF.*/ 32 | #define PgmPrintln(x) SerialPrintln_P(PSTR(x)) 33 | /** Defined so doxygen works for function definitions. */ 34 | #endif 35 | #define NOINLINE __attribute__((noinline,unused)) 36 | #define UNUSEDOK __attribute__((unused)) 37 | //------------------------------------------------------------------------------ 38 | /** Return the number of bytes currently free in RAM. */ 39 | #ifdef RASPI 40 | static UNUSEDOK int FreeRam(void){ return 1024*1024; } 41 | #else 42 | static UNUSEDOK int FreeRam(void) { 43 | extern int __bss_end; 44 | extern int* __brkval; 45 | int free_memory; 46 | if (reinterpret_cast(__brkval) == 0) { 47 | // if no heap use from end of bss section 48 | free_memory = reinterpret_cast(&free_memory) 49 | - reinterpret_cast(&__bss_end); 50 | } else { 51 | // use from top of stack to heap 52 | free_memory = reinterpret_cast(&free_memory) 53 | - reinterpret_cast(__brkval); 54 | } 55 | return free_memory; 56 | } 57 | #endif 58 | #ifdef __AVR__ 59 | //------------------------------------------------------------------------------ 60 | /** 61 | * %Print a string in flash memory to the serial port. 62 | * 63 | * \param[in] str Pointer to string stored in flash memory. 64 | */ 65 | static NOINLINE void SerialPrint_P(PGM_P str) { 66 | for (uint8_t c; (c = pgm_read_byte(str)); str++) Serial.write(c); 67 | } 68 | //------------------------------------------------------------------------------ 69 | /** 70 | * %Print a string in flash memory followed by a CR/LF. 71 | * 72 | * \param[in] str Pointer to string stored in flash memory. 73 | */ 74 | static NOINLINE void SerialPrintln_P(PGM_P str) { 75 | SerialPrint_P(str); 76 | Serial.println(); 77 | } 78 | #endif // __AVR__ 79 | #endif // #define SdFatUtil_h 80 | -------------------------------------------------------------------------------- /libraries/SPI/SPI.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SPI Master library for Raspberry Pi Arduino. 3 | Copyright (c) 2015 by Hristo Gochkov 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "pins_arduino.h" 21 | #include "SPI.h" 22 | 23 | void SPIClass::begin() { 24 | pinMode(9, ALT0); 25 | pinMode(10, ALT0); 26 | pinMode(11, ALT0); 27 | SPI0CLK = SPI0F2DIV(1000000);//1MHz 28 | SPI0CS = _BV(SPI0CLEAR_RX) | _BV(SPI0CLEAR_TX); 29 | } 30 | 31 | void SPIClass::end() { 32 | pinMode(9, INPUT); 33 | pinMode(10, INPUT); 34 | pinMode(11, INPUT); 35 | SPI0CS = _BV(SPI0CLEAR_RX) | _BV(SPI0CLEAR_TX); 36 | } 37 | 38 | void SPIClass::setDataMode(uint32_t mode){ 39 | SPI0CS &= ~SPI_MODE3; 40 | SPI0CS |= mode; 41 | } 42 | 43 | void SPIClass::setClockDivider(uint32_t rate){ 44 | SPI0CLK = rate; 45 | } 46 | 47 | void SPIClass::setClock(uint32_t rate){ 48 | setClockDivider(SPI0F2DIV(rate)); 49 | } 50 | 51 | uint8_t SPIClass::transfer(uint8_t data) { 52 | SPI0CS |= _BV(SPI0TA) | _BV(SPI0CLEAR_RX) | _BV(SPI0CLEAR_TX); 53 | SPI0FIFO = data; 54 | while (!(SPI0CS & _BV(SPI0RXD))); 55 | uint32_t ret = SPI0FIFO; 56 | SPI0CS &= ~_BV(SPI0TA); 57 | return ret; 58 | } 59 | 60 | void SPIClass::beginTransaction(SPISettings settings){ 61 | SPI0CLK = SPI0F2DIV(settings.freq); 62 | SPI0CS &= ~SPI_MODE3; 63 | SPI0CS |= settings.mode; 64 | } 65 | 66 | SPIClass SPI; 67 | -------------------------------------------------------------------------------- /libraries/SPI/SPI.h: -------------------------------------------------------------------------------- 1 | /* 2 | SPI Master library for Raspberry Pi Arduino. 3 | Copyright (c) 2015 by Hristo Gochkov 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef _SPI_H_INCLUDED 21 | #define _SPI_H_INCLUDED 22 | 23 | #include 24 | #include "Arduino.h" 25 | 26 | #define SPI_HAS_TRANSACTION 27 | 28 | //AVR Arduino compatibility 29 | #define SPI_CLOCK_DIV2 SPI0F2DIV(8000000) 30 | #define SPI_CLOCK_DIV4 SPI0F2DIV(4000000) 31 | #define SPI_CLOCK_DIV8 SPI0F2DIV(1000000) 32 | #define SPI_CLOCK_DIV16 SPI0F2DIV(500000) 33 | #define SPI_CLOCK_DIV32 SPI0F2DIV(250000) 34 | #define SPI_CLOCK_DIV64 SPI0F2DIV(175000) 35 | #define SPI_CLOCK_DIV128 SPI0F2DIV(87500) 36 | 37 | #define SPI_MODE0 SPI0MODE0 38 | #define SPI_MODE1 SPI0MODE1 39 | #define SPI_MODE2 SPI0MODE2 40 | #define SPI_MODE3 SPI0MODE3 41 | 42 | class SPISettings { 43 | public: 44 | SPISettings():freq(4000000),mode(SPI_MODE0){} 45 | SPISettings(uint32_t clockFreq, uint8_t bitOrder, uint8_t dataMode) { 46 | freq = clockFreq; 47 | mode = dataMode & SPI0MODE3; 48 | } 49 | private: 50 | uint32_t freq; 51 | uint8_t mode; 52 | friend class SPIClass; 53 | }; 54 | 55 | 56 | class SPIClass { 57 | public: 58 | static void begin(); 59 | static void end(); 60 | static void setDataMode(uint32_t); 61 | static void setClockDivider(uint32_t); 62 | static void setClock(uint32_t); 63 | static void beginTransaction(SPISettings settings); 64 | static uint8_t transfer(uint8_t data); 65 | inline static void endTransaction(void){} 66 | //no bit order on the pi 67 | inline static void setBitOrder(uint32_t){} 68 | }; 69 | 70 | extern SPIClass SPI; 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Digital Pot Control 3 | 4 | This example controls an Analog Devices AD5206 digital potentiometer. 5 | The AD5206 has 6 potentiometer channels. Each channel's pins are labeled 6 | A - connect this to voltage 7 | W - this is the pot's wiper, which changes when you set it 8 | B - connect this to ground. 9 | 10 | The AD5206 is SPI-compatible,and to command it, you send two bytes, 11 | one with the channel number (0 - 5) and one with the resistance value for the 12 | channel (0 - 255). 13 | 14 | The circuit: 15 | * All A pins of AD5206 connected to +5V 16 | * All B pins of AD5206 connected to ground 17 | * An LED and a 220-ohm resisor in series connected from each W pin to ground 18 | * CS - to digital pin 10 (SS pin) 19 | * SDI - to digital pin 11 (MOSI pin) 20 | * CLK - to digital pin 13 (SCK pin) 21 | 22 | created 10 Aug 2010 23 | by Tom Igoe 24 | 25 | Thanks to Heather Dewey-Hagborg for the original tutorial, 2005 26 | 27 | */ 28 | 29 | 30 | // inslude the SPI library: 31 | #include 32 | 33 | 34 | // set pin 10 as the slave select for the digital pot: 35 | const int slaveSelectPin = 10; 36 | 37 | void setup() { 38 | // set the slaveSelectPin as an output: 39 | pinMode(slaveSelectPin, OUTPUT); 40 | // initialize SPI: 41 | SPI.begin(); 42 | } 43 | 44 | void loop() { 45 | // go through the six channels of the digital pot: 46 | for (int channel = 0; channel < 6; channel++) { 47 | // change the resistance on this channel from min to max: 48 | for (int level = 0; level < 255; level++) { 49 | digitalPotWrite(channel, level); 50 | delay(10); 51 | } 52 | // wait a second at the top: 53 | delay(100); 54 | // change the resistance on this channel from max to min: 55 | for (int level = 0; level < 255; level++) { 56 | digitalPotWrite(channel, 255 - level); 57 | delay(10); 58 | } 59 | } 60 | 61 | } 62 | 63 | void digitalPotWrite(int address, int value) { 64 | // take the SS pin low to select the chip: 65 | digitalWrite(slaveSelectPin, LOW); 66 | // send in the address and value via SPI: 67 | SPI.transfer(address); 68 | SPI.transfer(value); 69 | // take the SS pin high to de-select the chip: 70 | digitalWrite(slaveSelectPin, HIGH); 71 | } 72 | -------------------------------------------------------------------------------- /libraries/SPI/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map SPI 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | SPI KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | begin KEYWORD2 15 | end KEYWORD2 16 | transfer KEYWORD2 17 | setBitOrder KEYWORD2 18 | setDataMode KEYWORD2 19 | setClockDivider KEYWORD2 20 | 21 | 22 | ####################################### 23 | # Constants (LITERAL1) 24 | ####################################### 25 | SPI_CLOCK_DIV4 LITERAL1 26 | SPI_CLOCK_DIV16 LITERAL1 27 | SPI_CLOCK_DIV64 LITERAL1 28 | SPI_CLOCK_DIV128 LITERAL1 29 | SPI_CLOCK_DIV2 LITERAL1 30 | SPI_CLOCK_DIV8 LITERAL1 31 | SPI_CLOCK_DIV32 LITERAL1 32 | SPI_CLOCK_DIV64 LITERAL1 33 | SPI_MODE0 LITERAL1 34 | SPI_MODE1 LITERAL1 35 | SPI_MODE2 LITERAL1 36 | SPI_MODE3 LITERAL1 -------------------------------------------------------------------------------- /libraries/SPI/library.properties: -------------------------------------------------------------------------------- 1 | name=SPI 2 | version=1.0 3 | author=Arduino 4 | maintainer=me-no-dev 5 | sentence=Enables the communication with devices that use the Serial Peripheral Interface (SPI) Bus. For Raspberry PI. 6 | paragraph= 7 | category=Communication 8 | url=http://www.arduino.cc/en/Reference/SPI 9 | architectures=* 10 | 11 | -------------------------------------------------------------------------------- /libraries/TTY/TTY.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Server.h - Server class for Raspberry Pi 3 | Copyright (c) 2016 Hristo Gochkov All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "TTY.h" 21 | 22 | #include 23 | #include 24 | 25 | uint8_t TTYClass::_put_c(uint8_t c){ 26 | return ioctl(_fd, TIOCSTI, &c) != -1; 27 | } 28 | 29 | TTYClass::TTYClass(uint8_t tty){ 30 | sprintf(_tty,"/dev/tty%u", tty); 31 | _fd = open(_tty, O_RDWR); 32 | } 33 | TTYClass::~TTYClass(){ 34 | end(); 35 | } 36 | void TTYClass::end(){ 37 | if(_fd > 0) 38 | close(_fd); 39 | _fd = 0; 40 | } 41 | size_t TTYClass::write(uint8_t c){ 42 | if(_fd <= 0) 43 | return 0; 44 | if(!_put_c(c)){ 45 | end(); 46 | return 0; 47 | } 48 | return 1; 49 | } 50 | size_t TTYClass::println(void){ 51 | return print('\n'); 52 | } 53 | 54 | TTYClass TTY1(1); 55 | -------------------------------------------------------------------------------- /libraries/TTY/TTY.h: -------------------------------------------------------------------------------- 1 | /* 2 | Server.h - TTY class for Raspberry Pi 3 | Copyright (c) 2016 Hristo Gochkov All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef pi_tty_h 21 | #define pi_tty_h 22 | 23 | #include "Arduino.h" 24 | #include "Print.h" 25 | 26 | #define TTY_SIGINT 3 //^C 27 | #define TTY_EOF 4 //^D 28 | #define TTY_BCKSPACE 8 //\b 29 | #define TTY_TAB 9 //\t 30 | #define TTY_LINE 10 //\n 31 | #define TTY_ENTER 13 //\r 32 | #define TTY_FLUSH 15 //^O 33 | #define TTY_START 17 //^Q 34 | #define TTY_ZPRINT 18 //^R 35 | #define TTY_STOP 19 //^S 36 | #define TTY_KILL 21 //^U 37 | #define TTY_LNEXT 22 //^V 38 | #define TTY_WERASE 23 //^W 39 | #define TTY_SUSUPEND 26 //^Z 40 | #define TTY_ESC 27 41 | #define TTY_QUIT 28 //^/ 42 | #define TTY_SPACE 32 //\s 43 | #define TTY_DEL 127 44 | #define TTY_F1 "\x1B" "OP" 45 | #define TTY_F2 "\x1B" "OQ" 46 | #define TTY_F3 "\x1B" "OR" 47 | #define TTY_F4 "\x1B" "OS" 48 | #define TTY_F5 "\x1B" "[15~" 49 | #define TTY_F6 "\x1B" "[17~" 50 | #define TTY_F7 "\x1B" "[18~" 51 | #define TTY_F8 "\x1B" "[19~" 52 | #define TTY_F9 "\x1B" "[20~" 53 | #define TTY_F10 "\x1B" "[21~" 54 | #define TTY_F11 "\x1B" "[23~" 55 | #define TTY_F12 "\x1B" "[24~" 56 | #define TTY_CTRL(c) ((char)(c) ^ 0x40) 57 | 58 | class TTYClass : public Print { 59 | private: 60 | char _tty[16]; 61 | int _fd; 62 | uint8_t _put_c(uint8_t c); 63 | 64 | public: 65 | operator bool(){return _fd > 0;} 66 | TTYClass(uint8_t tty); 67 | ~TTYClass(); 68 | void end(); 69 | size_t write(uint8_t c); 70 | size_t println(void); 71 | using Print::println; 72 | }; 73 | 74 | extern TTYClass TTY1; 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /libraries/TTY/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map SPI 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | TTY KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | begin KEYWORD2 15 | end KEYWORD2 16 | 17 | ####################################### 18 | # Constants (LITERAL1) 19 | ####################################### 20 | -------------------------------------------------------------------------------- /libraries/TTY/library.properties: -------------------------------------------------------------------------------- 1 | name=TTY 2 | version=1.0 3 | author=Arduino 4 | maintainer=me-no-dev 5 | sentence=Enables writing and executing commands running on PIs main tty console 6 | paragraph= 7 | category=Communication 8 | url= 9 | architectures=* 10 | 11 | -------------------------------------------------------------------------------- /libraries/Wire/Wire.h: -------------------------------------------------------------------------------- 1 | /* 2 | TwoWire.h - TWI/I2C library for Arduino & Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts 20 | */ 21 | 22 | #ifndef TwoWire_h 23 | #define TwoWire_h 24 | 25 | #include 26 | 27 | #ifdef __cplusplus 28 | extern "C"{ 29 | #endif 30 | 31 | extern uint8_t TWBR; 32 | 33 | #ifdef __cplusplus 34 | } // extern "C" 35 | #endif 36 | 37 | #include "Stream.h" 38 | 39 | #define BUFFER_LENGTH 32 40 | 41 | class TwoWire : public Stream { 42 | private: 43 | static uint8_t rxBuffer[]; 44 | static uint8_t rxBufferIndex; 45 | static uint8_t rxBufferLength; 46 | 47 | static uint8_t txAddress; 48 | static uint8_t txBuffer[]; 49 | static uint8_t txBufferIndex; 50 | static uint8_t txBufferLength; 51 | 52 | public: 53 | TwoWire(); 54 | void begin(); 55 | void end(); 56 | void begin(uint8_t); 57 | void setClock(uint32_t); 58 | void beginTransmission(uint8_t); 59 | uint8_t endTransmission(void); 60 | uint8_t endTransmission(uint8_t); 61 | uint8_t requestFrom(uint8_t, uint8_t); 62 | uint8_t requestFrom(uint8_t, uint8_t, uint8_t); 63 | virtual size_t write(uint8_t); 64 | virtual size_t write(const uint8_t *, size_t); 65 | virtual int available(void); 66 | virtual int read(void); 67 | virtual int peek(void); 68 | virtual void flush(void){} 69 | 70 | inline size_t write(unsigned long n) { return write((uint8_t)n); } 71 | inline size_t write(long n) { return write((uint8_t)n); } 72 | inline size_t write(unsigned int n) { return write((uint8_t)n); } 73 | inline size_t write(int n) { return write((uint8_t)n); } 74 | using Print::write; 75 | }; 76 | 77 | extern TwoWire Wire; 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino: -------------------------------------------------------------------------------- 1 | // I2C SRF10 or SRF08 Devantech Ultrasonic Ranger Finder 2 | // by Nicholas Zambetti 3 | // and James Tichenor 4 | 5 | // Demonstrates use of the Wire library reading data from the 6 | // Devantech Utrasonic Rangers SFR08 and SFR10 7 | 8 | // Created 29 April 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() { 16 | Wire.begin(); // join i2c bus (address optional for master) 17 | Serial.begin(9600); // start serial communication at 9600bps 18 | } 19 | 20 | int reading = 0; 21 | 22 | void loop() { 23 | // step 1: instruct sensor to read echoes 24 | Wire.beginTransmission(112); // transmit to device #112 (0x70) 25 | // the address specified in the datasheet is 224 (0xE0) 26 | // but i2c adressing uses the high 7 bits so it's 112 27 | Wire.write(byte(0x00)); // sets register pointer to the command register (0x00) 28 | Wire.write(byte(0x50)); // command sensor to measure in "inches" (0x50) 29 | // use 0x51 for centimeters 30 | // use 0x52 for ping microseconds 31 | Wire.endTransmission(); // stop transmitting 32 | 33 | // step 2: wait for readings to happen 34 | delay(70); // datasheet suggests at least 65 milliseconds 35 | 36 | // step 3: instruct sensor to return a particular echo reading 37 | Wire.beginTransmission(112); // transmit to device #112 38 | Wire.write(byte(0x02)); // sets register pointer to echo #1 register (0x02) 39 | Wire.endTransmission(); // stop transmitting 40 | 41 | // step 4: request reading from sensor 42 | Wire.requestFrom(112, 2); // request 2 bytes from slave device #112 43 | 44 | // step 5: receive reading from sensor 45 | if (2 <= Wire.available()) { // if two bytes were received 46 | reading = Wire.read(); // receive high byte (overwrites previous reading) 47 | reading = reading << 8; // shift high byte to be high 8 bits 48 | reading |= Wire.read(); // receive low byte as lower 8 bits 49 | Serial.println(reading); // print the reading 50 | } 51 | 52 | delay(250); // wait a bit since people have to read the output :) 53 | } 54 | 55 | 56 | /* 57 | 58 | // The following code changes the address of a Devantech Ultrasonic Range Finder (SRF10 or SRF08) 59 | // usage: changeAddress(0x70, 0xE6); 60 | 61 | void changeAddress(byte oldAddress, byte newAddress) 62 | { 63 | Wire.beginTransmission(oldAddress); 64 | Wire.write(byte(0x00)); 65 | Wire.write(byte(0xA0)); 66 | Wire.endTransmission(); 67 | 68 | Wire.beginTransmission(oldAddress); 69 | Wire.write(byte(0x00)); 70 | Wire.write(byte(0xAA)); 71 | Wire.endTransmission(); 72 | 73 | Wire.beginTransmission(oldAddress); 74 | Wire.write(byte(0x00)); 75 | Wire.write(byte(0xA5)); 76 | Wire.endTransmission(); 77 | 78 | Wire.beginTransmission(oldAddress); 79 | Wire.write(byte(0x00)); 80 | Wire.write(newAddress); 81 | Wire.endTransmission(); 82 | } 83 | 84 | */ 85 | -------------------------------------------------------------------------------- /libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino: -------------------------------------------------------------------------------- 1 | // I2C Digital Potentiometer 2 | // by Nicholas Zambetti 3 | // and Shawn Bonkowski 4 | 5 | // Demonstrates use of the Wire library 6 | // Controls AD5171 digital potentiometer via I2C/TWI 7 | 8 | // Created 31 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | // This example code is in the public domain. 13 | 14 | 15 | #include 16 | 17 | void setup() { 18 | Wire.begin(); // join i2c bus (address optional for master) 19 | } 20 | 21 | byte val = 0; 22 | 23 | void loop() { 24 | Wire.beginTransmission(44); // transmit to device #44 (0x2c) 25 | // device address is specified in datasheet 26 | Wire.write(byte(0x00)); // sends instruction byte 27 | Wire.write(val); // sends potentiometer value byte 28 | Wire.endTransmission(); // stop transmitting 29 | 30 | val++; // increment value 31 | if (val == 64) { // if reached 64th position (max) 32 | val = 0; // start over from lowest value 33 | } 34 | delay(500); 35 | } 36 | 37 | -------------------------------------------------------------------------------- /libraries/Wire/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Wire 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | ####################################### 10 | # Methods and Functions (KEYWORD2) 11 | ####################################### 12 | 13 | begin KEYWORD2 14 | setClock KEYWORD2 15 | beginTransmission KEYWORD2 16 | endTransmission KEYWORD2 17 | requestFrom KEYWORD2 18 | 19 | ####################################### 20 | # Instances (KEYWORD2) 21 | ####################################### 22 | 23 | Wire KEYWORD2 24 | 25 | ####################################### 26 | # Constants (LITERAL1) 27 | ####################################### 28 | 29 | -------------------------------------------------------------------------------- /libraries/Wire/library.properties: -------------------------------------------------------------------------------- 1 | name=Wire 2 | version=1.0 3 | author=Arduino 4 | maintainer=me-no-dev 5 | sentence=Allows the communication between devices or sensors connected via Two Wire Interface Bus. For Raspberry PI Arduino. 6 | paragraph= 7 | category=Communication 8 | url=http://www.arduino.cc/en/Reference/Wire 9 | architectures=* 10 | 11 | -------------------------------------------------------------------------------- /libraries/Wire/utility/twi.c: -------------------------------------------------------------------------------- 1 | /* 2 | I2C Master library for Raspberry Pi Arduino. 3 | Copyright (c) 2015 by Hristo Gochkov 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | #include "Arduino.h" 20 | #include "twi.h" 21 | 22 | uint8_t TWBR; 23 | 24 | uint8_t twi_writeTo(uint8_t address, uint8_t * buf, uint32_t len, uint8_t var, uint8_t sendStop){ 25 | uint32_t remaining = len; 26 | uint32_t i = 0; 27 | uint8_t reason = 0; 28 | 29 | BSC1A = address; 30 | BSC1C |= _BV(BSCCLEAR); 31 | BSC1S = _BV(BSCCLKT) | _BV(BSCERR) | _BV(BSCDONE); 32 | BSC1DLEN = len; 33 | while(remaining && ( i < 16 )){ 34 | BSC1FIFO = buf[i]; 35 | i++; 36 | remaining--; 37 | } 38 | 39 | BSC1C = _BV(BSCI2CEN) | _BV(BSCST); 40 | while(!(BSC1S & _BV(BSCDONE))){ 41 | while(remaining && (BSC1S & _BV(BSCTXD))){ 42 | BSC1FIFO = buf[i]; 43 | i++; 44 | remaining--; 45 | } 46 | } 47 | 48 | if (BSC1S & _BV(BSCERR)){ 49 | reason = 1; 50 | } else if (BSC1S & _BV(BSCCLKT)){ 51 | reason = 2; 52 | } else if (remaining){ 53 | reason = 3; 54 | } 55 | BSC1C |= _BV(BSCDONE); 56 | return reason; 57 | } 58 | 59 | uint8_t twi_readFrom(uint8_t address, uint8_t* buf, uint32_t len, uint8_t sendStop){ 60 | uint32_t remaining = len; 61 | uint32_t i = 0; 62 | uint8_t reason = 0; 63 | 64 | BSC1A = address; 65 | BSC1C |= _BV(BSCCLEAR); 66 | BSC1S = _BV(BSCCLKT) | _BV(BSCERR) | _BV(BSCDONE); 67 | BSC1DLEN = len; 68 | BSC1C = _BV(BSCI2CEN) | _BV(BSCST) | _BV(BSCREAD); 69 | 70 | while(!(BSC1S & _BV(BSCDONE))){ 71 | while (BSC1S & _BV(BSCRXD)){ 72 | buf[i] = BSC1FIFO; 73 | i++; 74 | remaining--; 75 | } 76 | } 77 | 78 | while (remaining && (BSC1S & _BV(BSCRXD))){ 79 | buf[i] = BSC1FIFO; 80 | i++; 81 | remaining--; 82 | } 83 | 84 | if (BSC1S & _BV(BSCERR)){ 85 | reason = 1; 86 | } else if (BSC1S & _BV(BSCCLKT)){ 87 | reason = 2; 88 | } else if (remaining){ 89 | reason = 3; 90 | } 91 | BSC1C |= _BV(BSCDONE); 92 | return reason; 93 | } 94 | -------------------------------------------------------------------------------- /libraries/Wire/utility/twi.h: -------------------------------------------------------------------------------- 1 | #ifndef twi_h 2 | #define twi_h 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C"{ 8 | #endif 9 | 10 | extern uint8_t TWBR; 11 | 12 | uint8_t twi_readFrom(uint8_t, uint8_t*, uint32_t, uint8_t); 13 | uint8_t twi_writeTo(uint8_t, uint8_t*, uint32_t, uint8_t, uint8_t); 14 | 15 | #ifdef __cplusplus 16 | } // extern "C" 17 | #endif 18 | 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /programmers.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me-no-dev/RasPiArduino/29fad57fa5d42cece2d5370831ba8f2a47b373c2/programmers.txt -------------------------------------------------------------------------------- /tools/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | -------------------------------------------------------------------------------- /tools/Makefile: -------------------------------------------------------------------------------- 1 | $(info Current directory is $(PWD)) 2 | 3 | # The Variant of the build 4 | VARIANT=bplus 5 | 6 | CORE = ../cores/piduino 7 | #dir to use for build temp 8 | BUILDDIR = build 9 | 10 | TOOLCHAINPREFIX = arm-linux-gnueabihf- 11 | 12 | DEBUG= 13 | #name of the output binary (the current folder name is used) 14 | OUTPUT_DYNAMIC = $(BUILDDIR)/libPiDuino.so 15 | OUTPUT_STATIC = $(BUILDDIR)/libPiDuino.a 16 | 17 | #should not need to touch anything bellow 18 | CORESRCS = $(wildcard $(CORE)/*.cpp) $(wildcard $(CORE)/*.c) 19 | OBJS = $(patsubst $(CORE)/%, $(BUILDDIR)/%, $(filter-out %.cpp, $(filter-out %.c, $(CORESRCS:.c=.c.o) $(CORESRCS:.cpp=.cpp.o)))) 20 | 21 | CC = $(TOOLCHAINPREFIX)gcc 22 | CPP = $(TOOLCHAINPREFIX)g++ 23 | INCLUDE = -I$(CORE) -I../variants/$(VARIANT) 24 | CFLAGS = $(DEBUG) -fPIC -MD -Wall -Winline -pipe $(INCLUDE) -g 25 | LDFLAGS = -shared 26 | LDLIBS = -lpthread -lm 27 | 28 | all: mkBuildDir $(OUTPUT_DYNAMIC) 29 | 30 | mkBuildDir: 31 | mkdir -p $(BUILDDIR) 32 | 33 | $(OUTPUT_DYNAMIC): $(OBJS) 34 | @echo "[LD] $(OUTPUT_DYNAMIC)" 35 | $(CPP) -g -o $(OUTPUT_DYNAMIC) $(OBJS) $(LDFLAGS) $(LDLIBS) 36 | ar crv $(OUTPUT_STATIC) $(OBJS) 37 | 38 | $(BUILDDIR)/%.c.o: $(CORE)/%.c 39 | @echo "[CC] $<" 40 | $(CC) -c $(CFLAGS) $< -o $@ 41 | 42 | $(BUILDDIR)/%.cpp.o: $(CORE)/%.cpp 43 | @echo "[CP] $<" 44 | $(CPP) -c $(CFLAGS) $< -o $@ 45 | 46 | clean: 47 | @echo "Cleaning any previous builds" 48 | @rm -rf $(BUILDDIR) 49 | -------------------------------------------------------------------------------- /tools/arduino.service: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %h 5 | 6 | _arduino._tcp 7 | 22 8 | board=bplus 9 | 10 | -------------------------------------------------------------------------------- /tools/arpi_bins/merge-sketch-with-bootloader.lua: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #This script is called from Arduino IDE right after upload 3 | chmod 06755 /tmp/sketch.bin 4 | -------------------------------------------------------------------------------- /tools/arpi_bins/run-avrdude: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #called by Arduino IDE usually to upload the HEX to the MCU 3 | #here we use it to start the sketch 4 | LOGFILE="/run/sketch.log" 5 | SKETCH="/tmp/sketch.bin" 6 | 7 | BINNAME="arduino-sketch" 8 | DESTBIN="/usr/local/bin/$BINNAME" 9 | 10 | 11 | PIDS=`ps ax | grep telnet | grep -v grep | awk '{print $1}'` 12 | for pid in $PIDS; do 13 | echo "KILLING: $pid" 14 | kill -9 $pid > /dev/null 2>&1 15 | sleep 1 16 | done 17 | 18 | killall $BINNAME > /dev/null 2>&1 19 | mv $SKETCH $DESTBIN 20 | cd / 21 | $DESTBIN >> $LOGFILE 2>&1 & 22 | 23 | echo "Sketch Started" 24 | -------------------------------------------------------------------------------- /tools/arpi_bins/run-sketch: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #can be used to start a sketch 3 | LOGFILE="/run/sketch.log" 4 | BINNAME="arduino-sketch" 5 | DESTBIN="/usr/local/bin/$BINNAME" 6 | 7 | if [ ! -f "$DESTBIN" ]; then 8 | exit 1; 9 | fi 10 | 11 | PIDS=`ps ax | grep telnet | grep -v grep | awk '{print $1}'` 12 | for pid in $PIDS; do 13 | echo "KILLING: $pid" 14 | kill -9 $pid > /dev/null 2>&1 15 | sleep 1 16 | done 17 | 18 | killall $BINNAME > /dev/null 2>&1 19 | cd / 20 | $DESTBIN >> $LOGFILE 2>&1 & 21 | -------------------------------------------------------------------------------- /tools/arpi_bins/telnet: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #telnet wrapper to allow Arduino IDE to connect to us 3 | RUNNING=`ps ax | grep bin/telnet | grep -v grep | wc -l` 4 | PID=$$ 5 | 6 | if [ ! -e "/usr/bin/real_telnet" ];then 7 | ln -s /usr/bin/telnet /usr/bin/real_telnet 8 | fi 9 | 10 | if [ $RUNNING -gt 2 ]; then 11 | PIDS=`ps ax | grep bin/telnet | grep -v grep | awk '{print $1}'` 12 | for pid in $PIDS; do 13 | if [ $pid -lt $PID ]; then 14 | kill -9 $pid > /dev/null 2>&1 15 | sleep 1 16 | fi 17 | done 18 | fi 19 | 20 | RUNNING=`ps ax | grep real_telnet | grep -v grep | wc -l` 21 | if [ $RUNNING -gt 0 ]; then 22 | killall real_telnet > /dev/null 2>&1 23 | sleep 1 24 | fi 25 | 26 | real_telnet $@ #2>> /run/sketch.log 27 | -------------------------------------------------------------------------------- /tools/compat/include/avr/pgmspace.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /tools/upload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PI_HOST=$1 3 | PI_PORT=$2 4 | PI_PASS=$3 5 | PI_FILE=$4 6 | 7 | if [ $PI_PORT -eq 8266 ]; then 8 | PI_PORT=22 9 | fi 10 | 11 | if [ $PI_PASS == "no_pwd_found_in_code" ]; then 12 | scp -P $PI_PORT $PI_FILE root@$PI_HOST:/tmp/sketch.bin 13 | ssh -p $PI_PORT root@$PI_HOST '/usr/local/bin/merge-sketch-with-bootloader.lua' 14 | ssh -p $PI_PORT root@$PI_HOST '/usr/local/bin/run-avrdude' 15 | else 16 | expect -c "spawn scp -P $PI_PORT $PI_FILE root@$PI_HOST:/tmp/sketch.bin; expect \"password:\"; send \"$PI_PASS\\r\"; interact" 17 | expect -c "spawn ssh -p $PI_PORT root@$PI_HOST /usr/local/bin/merge-sketch-with-bootloader.lua; expect \"password:\"; send \"$PI_PASS\\r\"; interact" 18 | expect -c "spawn ssh -p $PI_PORT root@$PI_HOST /usr/local/bin/run-avrdude; expect \"password:\"; send \"$PI_PASS\\r\"; interact" 19 | fi 20 | -------------------------------------------------------------------------------- /variants/bplus/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef Pins_Arduino_h 2 | #define Pins_Arduino_h 3 | 4 | #include "bcm2835_registers.h" 5 | 6 | #define NOT_A_PIN 0 7 | #define NOT_A_PORT 0 8 | #define NOT_AN_INTERRUPT -1 9 | 10 | #define EXTERNAL_NUM_INTERRUPTS 32 11 | #define NUM_DIGITAL_PINS 32 12 | #define NUM_ANALOG_INPUTS 0 13 | 14 | #define analogInputToDigitalPin(p) (-1) 15 | #define analogInPinToBit(p) (p) 16 | 17 | #define digitalPinToPort(p) (((p)<32)?0:1) 18 | #define digitalPinToBitMask(p) (1 << p) 19 | #define portOutputRegister(p) ((volatile uint32_t *)((p)?&GPSET1:&GPSET0)) 20 | #define portModeRegister(p) ((volatile uint32_t *)((p)?&GPSET1:&GPSET0)) 21 | 22 | #define digitalPinHasPWM(p) ((p) == 12 || (p) == 13 || (p) == 18 || (p) == 19) 23 | #define digitalPinToInterrupt(p) (p) 24 | #define digitalPinToTimer(p) ((p==12||p==18)?0:(p==13||p==19)?1:-1) 25 | 26 | //*portModeRegister(digitalPinToPort(ETHERNET_SHIELD_SPI_CS)) |= digitalPinToBitMask(ETHERNET_SHIELD_SPI_CS); 27 | 28 | // A/B - 17 GPIO | A+/B+/2/Zero - 28 GPIO 29 | // RX, TX, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, A0, A1, A2, A3, A4, A5, SDA, SCL, SCK, MISO, MOSI, RST 30 | //const uint8_t piToArduinoB[26] = { 15, 14, 4, 18, 7, 22, 23, 24, 25, 17, 8, 10, 9, 11, 28, 29, 30, 31, 2, 3, 2, 3, 11, 9, 10, 27 }; 31 | //const uint8_t piToArduinoBP[26] = { 15, 14, 4, 18, 7, 22, 23, 24, 25, 17, 8, 12, 16, 13, 5, 19, 20, 21, 6, 26, 2, 3, 11, 9, 10, 27 }; 32 | 33 | static const uint8_t ID_SD = 0; //pin 27 //B+ 34 | static const uint8_t ID_SC = 1; //pin 28 //B+ 35 | static const uint8_t SDA = 2; //pin 3 36 | static const uint8_t SCL = 3; //pin 5 37 | //static const uint8_t D4 = 4; //pin 7 38 | //static const uint8_t D5 = 5; //pin 29 //B+ 39 | //static const uint8_t D6 = 6; //pin 31 //B+ 40 | static const uint8_t SS1 = 7; //pin 26 41 | static const uint8_t SS = 8; //pin 24 42 | static const uint8_t MISO = 9; //pin 21 43 | static const uint8_t MOSI = 10;//pin 19 44 | static const uint8_t SCK = 11;//pin 23 45 | static const uint8_t PWM00 = 12;//pin 32 //B+ 46 | static const uint8_t PWM01 = 13;//pin 33 //B+ 47 | static const uint8_t TX = 14;//pin 8 48 | static const uint8_t RX = 15;//pin 10 49 | //static const uint8_t D16 = 16;//pin 36 //B+ 50 | //static const uint8_t D17 = 17;//pin 11 51 | static const uint8_t PWM10 = 18;//pin 12 //PCM_CLK 52 | static const uint8_t PWM11 = 19;//pin 35 //B+ //PCM_FS 53 | //static const uint8_t D20 = 20;//pin 38 //B+ //PCM_DIN 54 | //static const uint8_t D21 = 21;//pin 40 //B+ //PCM_DOUT 55 | //static const uint8_t D22 = 22;//pin 15 56 | //static const uint8_t D23 = 23;//pin 16 57 | //static const uint8_t D24 = 24;//pin 18 58 | //static const uint8_t D25 = 25;//pin 22 59 | //static const uint8_t D26 = 26;//pin 37 //B+ 60 | //static const uint8_t D27 = 27;//pin 13 61 | //static const uint8_t D28 = 28;//pin //A/B //PCM_CLK //ID_SD 62 | //static const uint8_t D29 = 29;//pin //A/B //PCM_FS //ID_SC 63 | //static const uint8_t D30 = 30;//pin //A/B //PCM_DIN 64 | //static const uint8_t D31 = 31;//pin //A/B //PCM_DOUT 65 | 66 | #define SERIAL_PORT_USBVIRTUAL Console 67 | #define SERIAL_PORT_MONITOR Console 68 | #define SERIAL_PORT_HARDWARE Serial 69 | 70 | #endif 71 | --------------------------------------------------------------------------------