GithubHelp home page GithubHelp logo

nlamprian / arduinopixel Goto Github PK

View Code? Open in Web Editor NEW
33.0 33.0 14.0 2.07 MB

An Android app that communicates with an Arduino web server to control a NeoPixel LED strip.

License: MIT License

Java 31.15% C++ 62.55% C 1.48% Shell 3.22% Python 1.59%

arduinopixel's Introduction

Hi there, I'm Nick 👋

I'm a nerd and a technology enthusiast

  • 👷 I’m currently working on robotics simulations and DevOps
  • 📔 In the past, I've worked on topics such as mapping, path planning, and control
  • :octocat: I love open source, and I'm always eager to contribute
  • 🌱 My current research topics involve computer vision

Connect with me:

codeSTACKr.com codeSTACKr | LinkedIn codeSTACKr | Twitter codeSTACKr | YouTube


Languages and Tools:

Cplusplus

Python

GitHub

Ubuntu

Bash

CMake

Arduino

ROS

SublimeText

LaTeX

Thingiverse

TrueNAS

Docker



📖 Latest Blog Posts

For more blog posts, visit nlamprian.me


nlamprian's GitHub stats Top Langs

arduinopixel's People

Contributors

nlamprian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduinopixel's Issues

Mode_Base.H

Hi, sorry new to this. An ESP32 . Trying to compile i constantly get the below error message. Mode_base.h is in the correct directory and i can see it in the arduino sketch window.

led_strip_base.h:32:28: error: mode/mode_base.h: No such file or directory

compilation terminated.

exit status 1
mode/mode_base.h: No such file or directory

ESP8266

Now that Arduino IDE supports ESP8266, it would be cool if you added support for it to your project :).

Thanks!

[Feature request] App mode selection

Your api suggest mode selection although application does not provide a way of listing and selecting modes, would be cool if someone implemented it.

WiFi

Hi,
More of a request/help post really...
I have just purchased an Arduino Yun Mini and wanted to try ArduinoPixel on it.
I realised it was including Ethernet.h so I included WiFi.h, WiFiClient.h, WiFiServer.h & WiFiUdp.h and replaced 'Ethernet' with 'WiFi' in the sketch.
But now I seem to be getting errors...

Any help would be appreciated. Thanks.

Original code:

Arduino: 1.6.5 (Mac OS X), Board: "Arduino Yún"

Build options changed, rebuilding all
Using library Adafruit NeoPixel in folder: /Users/craigfews/Documents/Arduino/libraries/Adafruit_NeoPixel 
Using library SPI in folder: /Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI 
Using library Ethernet in folder: /Applications/Tools/Arduino.app/Contents/Java/libraries/Ethernet 

/Applications/Tools/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_YUN -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8041 -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Yun" -I/Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/variants/yun -I/Users/craigfews/Documents/Arduino/libraries/Adafruit_NeoPixel -I/Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI -I/Applications/Tools/Arduino.app/Contents/Java/libraries/Ethernet/src /var/folders/8l/hkfn98n10gd3zfxzd6pkxg180000gn/T/build491980951959006376.tmp/ArduinoPixel.cpp -o /var/folders/8l/hkfn98n10gd3zfxzd6pkxg180000gn/T/build491980951959006376.tmp/ArduinoPixel.cpp.o 
ArduinoPixel.ino: In function 'void loop()':
ArduinoPixel.ino:185:62: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:70:6: error:   initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:196:55: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:70:6: error:   initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:203:55: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:70:6: error:   initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:212:54: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:70:6: error:   initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:216:62: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:70:6: error:   initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:221:54: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:70:6: error:   initializing argument 4 of 'void respond(int, const char*, boolean, String)'
converting to 'String' from initializer list would use explicit constructor 'String::String(char)'

With 'Ethernet' replaced with 'WiFi':
Sketch:

#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
#include <Adafruit_NeoPixel.h>
#include <SPI.h>
#include <Ethernet.h>

// #define DEBUG

// !!! Specify the pin and number of leds for your LED strip              <====<
const int STRIP_PIN = 8;
const int NUM_OF_LEDS_ON_STRIP = 60;

// !!! Specify the MAC address and IP address for your controller         <====<
// The IP address will be dependent on your local network
byte mac[] = { 0x80, 0xC2, 0x2A, 0x4E, 0x71, 0xD9 };
IPAddress ip(192, 168, 1, 100);  // You may leave this as is
const int PORT = 80;  // You may leave this as is

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_OF_LEDS_ON_STRIP, STRIP_PIN, NEO_GRB + NEO_KHZ800);

// Initializes an EthernetServer
// instance with port number
WiFiServer server(PORT);

WiFiClient client;

// HTTP request methods
enum Method
{
    GET,
    PUT
};

// Available URIs
enum Uri
{
    ROOT,        // "/"
    STATUS,      // "/strip/status/"
    COLOR_GET,   // "/strip/color/"
    STATUS_ON,   // "/strip/status/on/"
    STATUS_OFF,  // "/strip/status/off/"
    COLOR_PUT    // "/strip/color/"
};

// Specifies whether the LED strip is on or off
boolean power = false;

// Keeps the current color of the LED strip
uint8_t color[] = { 128, 128, 128 };


void setup() {
    #if defined(DEBUG)
    Serial.begin(9600);  // Initializes the Serial port
    while (!Serial) ;  // Needed for Leonardo only
    #endif

    // Starts the Ethernet connection and the server
    WiFi.begin(mac, ip);
    server.begin();

    #if defined(DEBUG)
    Serial.print("Server is at ");
    Serial.println(WiFi.localIP());
    Serial.println();
    #endif

    // Initializes the LED strip
    strip.begin();
    strip.show();
}

void loop()
{
    // If there is an available connection, 
    // it reads the request
    client = server.available();
    if (client) {
        uint8_t i = 0;
        char reqChar;
        char request[35];
        char buf[60];

        // Reads the request line
        while (client.available())
        {
            reqChar = client.read();

            if (reqChar != '\r')
            {
                request[i++] = reqChar;
            }
            else
            {
                client.read();  // Gets rid of '\n'
                request[i] = '\0';
                break;
            }
        }

        // Parses the request line
        int8_t method, uri;
        parseRequestLine(method, uri, String(request));

        // Initiates the appropriate response
        switch (method)
        {
            case GET:
                switch (uri)
                {
                    case ROOT:
                        respond(200, "OK", false, "Hello from Arduino Server");
                        break;

                    case STATUS:
                        respond(200, "OK", false, power?"ON":"OFF");
                        break;

                    case COLOR_GET:
                      {
                      String colorData = "{\"r\":" + String(color[0]) + 
                                         ",\"g\":" + String(color[1]) + 
                                         ",\"b\":" + String(color[2]) + "}";
                      respond(200, "OK", false, colorData);
                      }
                      break;

                    default:
                        respond(404, "Not Found", false, '\0');
                }
                break;

            case PUT:
                switch (uri)
                {
                    // Turns the LED strip on
                    case STATUS_ON:
                        power = true;
                        colorize(color[0], color[1], color[2]);
                        respond(200, "OK", false, '\0');
                        break;

                    // Turn the LED strip off
                    case STATUS_OFF:
                        power = false;
                        colorize(0, 0, 0);
                        respond(200, "OK", false, '\0');
                        break;

                    // Parses the JSON data (and updates the LED strip color)
                    case COLOR_PUT:
                        getJson(buf);  // Retrieves the JSON data
                        parseColors(String(buf));  // Parses the data
                        if (power)
                            colorize(color[0], color[1], color[2]);
                        respond(200, "OK", true, '\0');
                        break;

                    default:
                        respond(404, "Not Found", false, '\0');
                }
                break;

            default:
                respond(404, "Not Found", false, '\0');
        }
    }
}

// Parses the HTTP request line
// Parameters: method  - the method of the request
//             uri     - the requested uri
//             request - string that holds the request line
void parseRequestLine(int8_t& method, int8_t& uri, String request)
{
    #if defined(DEBUG)
    Serial.println(request);
    #endif

    // Parses the request method
    String reqMethod = request.substring(0, 3);
    if (reqMethod.equals("GET"))
        method = GET;
    else if (reqMethod.equals("PUT"))
        method = PUT;
    else
        method = -1;

    // Parses the URI
    String reqUri = request.substring(4, request.lastIndexOf(' '));
    if (reqUri.equals("/"))
        uri = ROOT;
    else if (reqUri.equals("/strip/status/"))
        uri = STATUS;
    else if (reqUri.equals("/strip/status/on/"))
        uri = STATUS_ON;
    else if (reqUri.equals("/strip/status/off/"))
        uri = STATUS_OFF;
    else if (reqUri.equals("/strip/color/"))
      if (method == GET)
        uri = COLOR_GET;
      else
          uri = COLOR_PUT;
    else
        uri = -1;

    #if defined(DEBUG)
    Serial.print("Method: ");
    Serial.println(method);
    Serial.print("URI: ");
    Serial.println(uri);
    Serial.println();
    #endif
}

// Sends an HTTP response
// Parameters: statusCode - Status code for the response line
//             statusMsg  - Status message for the response line
//             keepAlive  - Whether to keep the connection open or not
//             data       - Data to return to client
void respond(int statusCode, const char* statusMsg, boolean keepAlive, String data)
{
        #if defined(DEBUG)
        Serial.print("HTTP/1.1 ");
        Serial.print(statusCode);
        Serial.print(" ");
        Serial.println(statusMsg);
        if (!keepAlive) Serial.println("Connection: close");
        Serial.println();
        if (data) { Serial.print(data);
                    Serial.println();
                    Serial.println(); }
        #endif

        client.print("HTTP/1.1 ");
        client.print(statusCode);
        client.print(" ");
        client.println(statusMsg);
        if (!keepAlive) client.println("Connection: close");
        if (data) { client.println();
                    client.print(data); }
        delay(1);
        client.stop();
}

// Retrieves the JSON data
// Parameters: buf - the buffer the store the data
void getJson(char* buf)
{
    uint8_t i = 0;
    char prevlastCharRead = '\0';
    char lastCharRead;

    // Gets rid of request headers
    while (client.available())
    {
        lastCharRead = client.read();
        if (prevlastCharRead == '\r' && lastCharRead == '\n')
        {
            char c1 = '\0', c2 = '\0';
            if (client.available()) c1 = client.read();
            if (client.available()) c2 = client.read();
            if (c1 == '\r' && c2 == '\n') break;
        }
        prevlastCharRead = lastCharRead;
    }

    // Retrieves the JSON data
    while (client.available()) buf[i++] = client.read();
    buf[i] = '\0';

    #if defined(DEBUG)
    Serial.println(buf);
    Serial.println();
    #endif
}

// Parses the colors from the JSON data
// Parameters: json - Holds the data
void parseColors(String json)
{
    uint8_t idx = 0;
    for (uint8_t i = 0; i < 3; ++i)
    {
        while (json[idx++] != ':') ;
        uint8_t startIdx = idx;
        while (json[idx] != ',' && json[idx] != '}') idx++;
        uint8_t endIdx = idx;
        String colorStr = json.substring(startIdx, endIdx);
        color[i] = (uint8_t) colorStr.toInt();
    }
}

// Updates the LED strip
// Parameters: r - red color value
//             g - green color value
//             b - blue color value
void colorize(uint8_t r, uint8_t g, uint8_t b)
{
    for (uint16_t i = 0; i < strip.numPixels(); ++i)
        strip.setPixelColor(i, r, g, b);
    strip.show();
}

Errors:

Arduino: 1.6.5 (Mac OS X), Board: "Arduino Yún"

Using library WiFi in folder: /Applications/Tools/Arduino.app/Contents/Java/libraries/WiFi 
Using library Adafruit NeoPixel in folder: /Users/craigfews/Documents/Arduino/libraries/Adafruit_NeoPixel 
Using library SPI in folder: /Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI 
Using library Ethernet in folder: /Applications/Tools/Arduino.app/Contents/Java/libraries/Ethernet 

/Applications/Tools/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_YUN -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8041 -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Yun" -I/Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/variants/yun -I/Applications/Tools/Arduino.app/Contents/Java/libraries/WiFi/src -I/Users/craigfews/Documents/Arduino/libraries/Adafruit_NeoPixel -I/Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI -I/Applications/Tools/Arduino.app/Contents/Java/libraries/Ethernet/src /var/folders/8l/hkfn98n10gd3zfxzd6pkxg180000gn/T/build491980951959006376.tmp/ArduinoPixel.cpp -o /var/folders/8l/hkfn98n10gd3zfxzd6pkxg180000gn/T/build491980951959006376.tmp/ArduinoPixel.cpp.o 
ArduinoPixel.ino: In function 'void setup()':
ArduinoPixel.ino:119:23: error: invalid conversion from 'byte* {aka unsigned char*}' to 'char*' [-fpermissive]
In file included from ArduinoPixel.ino:59:0:
/Applications/Tools/Arduino.app/Contents/Java/libraries/WiFi/src/WiFi.h:79:9: error:   initializing argument 1 of 'int WiFiClass::begin(char*, const char*)' [-fpermissive]
     int begin(char* ssid, const char *passphrase);
         ^
ArduinoPixel.ino:119:23: error: invalid user-defined conversion from 'IPAddress' to 'const char*' [-fpermissive]
In file included from /Applications/Tools/Arduino.app/Contents/Java/libraries/WiFi/src/WiFi.h:30:0,
                 from ArduinoPixel.ino:59:
/Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/IPAddress.h:50:5: note: candidate is: IPAddress::operator uint32_t() const <near match>
     operator uint32_t() const { return _address.dword; };
     ^
/Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/IPAddress.h:50:5: note:   no known conversion for implicit 'this' parameter from 'uint32_t {aka long unsigned int}' to 'const char*'
ArduinoPixel.ino: In function 'void loop()':
ArduinoPixel.ino:189:62: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:74:6: error:   initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:200:55: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:74:6: error:   initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:207:55: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:74:6: error:   initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:216:54: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:74:6: error:   initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:220:62: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:74:6: error:   initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:225:54: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:74:6: error:   initializing argument 4 of 'void respond(int, const char*, boolean, String)'
invalid conversion from 'byte* {aka unsigned char*}' to 'char*' [-fpermissive]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.