Skip to content

Commit

Permalink
Merge branch 'jnsbyr-esp' into esp
Browse files Browse the repository at this point in the history
  • Loading branch information
soundanalogous committed Apr 11, 2016
2 parents c1bafb7 + 7ecba4e commit 985e34c
Show file tree
Hide file tree
Showing 14 changed files with 225 additions and 626 deletions.
33 changes: 20 additions & 13 deletions Boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -665,22 +665,26 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
#define PIN_TO_SERVO(p) ((p) - 2)

// ESP8266 generic
// ESP8266
// note: boot mode GPIOs 0, 2 and 15 can be used as outputs, GPIOs 6-11 are in use for flash IO
#elif defined(ESP8266)
#define TOTAL_ANALOG_PINS 0
#define TOTAL_PINS 17
#define VERSION_BLINK_PIN 4
// #define IS_PIN_DIGITAL(p) ((p) == 0 || (p) == 1 || (p) == 2 || (p) == 3 || (p) == 4 || (p) == 5 || (p) == 12 || (p) == 13 || (p) == 14 || (p) == 15 || (p) == 16) //for wifi dont protect serial pins because these things only have 2 pins otherwise
#define IS_PIN_DIGITAL(p) ((p) == 0 || (p) == 2 || (p) == 4 || (p) == 5 || (p) == 12 || (p) == 13 || (p) == 14 || (p) == 15 || (p) == 16)
#define IS_PIN_ANALOG(p) (false)
#define IS_PIN_PWM(p) (false)
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
#define IS_PIN_I2C(p) (false)
#define IS_PIN_SPI(p) (false)
#define TOTAL_ANALOG_PINS NUM_ANALOG_INPUTS
#define TOTAL_PINS A0 + NUM_ANALOG_INPUTS
#define PIN_SERIAL_RX 3
#define PIN_SERIAL_TX 1
#define IS_PIN_DIGITAL(p) (((p) >= 0 && (p) <= 5) || ((p) >= 12 && (p) < A0))
#define IS_PIN_ANALOG(p) ((p) >= A0 && (p) < A0 + NUM_ANALOG_INPUTS)
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
#define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) < MAX_SERVOS)
#define IS_PIN_I2C(p) ((p) == SDA || (p) == SCL)
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
#define IS_PIN_INTERRUPT(p) (digitalPinToInterrupt(p) > NOT_AN_INTERRUPT)
#define IS_PIN_SERIAL(p) ((p) == PIN_SERIAL_RX || (p) == PIN_SERIAL_TX)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) ((p) - 17)
#define PIN_TO_ANALOG(p) ((p) - A0)
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
#define PIN_TO_SERVO(p) p
#define PIN_TO_SERVO(p) (p)
#define DEFAULT_PWM_RESOLUTION 10


// anything else
Expand All @@ -697,6 +701,9 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define IS_PIN_SERIAL(p) 0
#endif

#ifndef DEFAULT_PWM_RESOLUTION
#define DEFAULT_PWM_RESOLUTION 8
#endif

/*==============================================================================
* readPort() - Read an 8 bit port
Expand Down
2 changes: 1 addition & 1 deletion examples/StandardFirmata/StandardFirmata.ino
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down
2 changes: 1 addition & 1 deletion examples/StandardFirmataChipKIT/StandardFirmataChipKIT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down
2 changes: 1 addition & 1 deletion examples/StandardFirmataPlus/StandardFirmataPlus.ino
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down
49 changes: 30 additions & 19 deletions examples/StandardFirmataWiFi/StandardFirmataWiFi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Copyright (C) 2009 Shigeru Kobayashi. All rights reserved.
Copyright (C) 2009-2016 Jeff Hoefs. All rights reserved.
Copyright (C) 2015-2016 Jesse Frush. All rights reserved.
Copyright (C) 2016 Jens B. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand All @@ -21,7 +22,7 @@
See file LICENSE.txt for further informations on licensing terms.
Last updated by Jeff Hoefs: January 10th, 2016
Last updated by Jeff Hoefs: April 10th, 2016
*/

/*
Expand All @@ -36,7 +37,7 @@
- Arduino WiFi Shield (or clone)
- Arduino WiFi Shield 101
- Arduino MKR1000 board (built-in WiFi 101)
- Adafruit HUZZAH CC3000 WiFi Shield (support coming soon)
- ESP8266 WiFi board compatible with ESP8266 Arduino core
Follow the instructions in the wifiConfig.h file (wifiConfig.h tab in Arduino IDE) to
configure your particular hardware.
Expand All @@ -45,6 +46,8 @@
- WiFi Shield 101 requires version 0.7.0 or higher of the WiFi101 library (available in Arduino
1.6.8 or higher, or update the library via the Arduino Library Manager or clone from source:
https://github.com/arduino-libraries/WiFi101)
- ESP8266 requires the Arduino ESP8266 core which can be obtained here:
https://github.com/esp8266/Arduino
In order to use the WiFi Shield 101 with Firmata you will need a board with at least
35k of Flash memory. This means you cannot use the WiFi Shield 101 with an Arduino Uno
Expand Down Expand Up @@ -74,11 +77,6 @@
#include <Wire.h>
#include <Firmata.h>

// I dont understand either
void disableI2CPins();
void enableI2CPins();
void reportAnalogCallback(byte analogPin, int value);

/*
* Uncomment the #define SERIAL_DEBUG line below to receive serial output messages relating to your
* connection that may help in the event of connection issues. If defined, some boards may not begin
Expand Down Expand Up @@ -125,6 +123,12 @@ SerialFirmata serialFeature;
#ifdef STATIC_IP_ADDRESS
IPAddress local_ip(STATIC_IP_ADDRESS);
#endif
#ifdef SUBNET_MASK
IPAddress subnet(SUBNET_MASK);
#endif
#ifdef GATEWAY_IP_ADDRESS
IPAddress gateway(GATEWAY_IP_ADDRESS);
#endif

int wifiConnectionAttemptCounter = 0;
int wifiStatus = WL_IDLE_STATUS;
Expand Down Expand Up @@ -692,7 +696,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down Expand Up @@ -822,37 +826,37 @@ void systemResetCallback()
}

void printWifiStatus() {
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
if ( WiFi.status() != WL_CONNECTED )
{
DEBUG_PRINT( "WiFi connection failed. Status value: " );
DEBUG_PRINTLN( WiFi.status() );
}
else
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
{
// print the SSID of the network you're attached to:
DEBUG_PRINT( "SSID: " );

#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
DEBUG_PRINTLN( WiFi.SSID() );
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)

// print your WiFi shield's IP address:
DEBUG_PRINT( "IP Address: " );

#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
IPAddress ip = WiFi.localIP();
DEBUG_PRINTLN( ip );
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)

// print the received signal strength:
DEBUG_PRINT( "signal strength (RSSI): " );

#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
long rssi = WiFi.RSSI();
DEBUG_PRINT( rssi );
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)

DEBUG_PRINTLN( " dBm" );
}
Expand All @@ -873,6 +877,8 @@ void setup()
DEBUG_PRINTLN( "using the WiFi 101 library." );
#elif defined(ARDUINO_WIFI_SHIELD)
DEBUG_PRINTLN( "using the legacy WiFi library." );
#elif defined(ESP8266_WIFI)
DEBUG_PRINTLN( "using the ESP8266 WiFi library." );
#elif defined(HUZZAH_WIFI)
DEBUG_PRINTLN( "using the HUZZAH WiFi library." );
//else should never happen here as error-checking in wifiConfig.h will catch this
Expand All @@ -884,9 +890,13 @@ void setup()
#ifdef STATIC_IP_ADDRESS
DEBUG_PRINT( "Using static IP: " );
DEBUG_PRINTLN( local_ip );
//you can also provide a static IP in the begin() functions, but this simplifies
//ifdef logic in this sketch due to support for all different encryption types.
#ifdef ESP8266_WIFI
stream.config( local_ip , gateway, subnet );
#else
// you can also provide a static IP in the begin() functions, but this simplifies
// ifdef logic in this sketch due to support for all different encryption types.
stream.config( local_ip );
#endif
#else
DEBUG_PRINTLN( "IP will be requested from DHCP ..." );
#endif
Expand Down Expand Up @@ -952,7 +962,8 @@ void setup()
|| 28 == i
#endif //defined(__AVR_ATmega32U4__)
) {
#elif defined (WIFI_101)
// don't ignore pins when using Wi-Fi 101 library with the MKR1000
#elif defined (WIFI_101) && !defined(ARDUINO_SAMD_MKR1000)
if (IS_IGNORE_WIFI101_SHIELD(i)) {
#elif defined (HUZZAH_WIFI)
// TODO
Expand Down
Loading

0 comments on commit 985e34c

Please sign in to comment.