Close
0%
0%

Cypress PSOC 4 + ESP8266 WS2812 RGB XMAS Lights

802.11 WIFI enabled RGB LED Strips, using the ESP8266 and $4 Psoc 4 dev board.

Similar projects worth following
802.11 WIFI Enabled RGB strip that can be fully controlled from an IP enabled host with UDP, it can also run standalone mode or be sent ID's to switch modes.

Uses Cypress PSOC 4, ESP8266 Wifi, VREG and logic level converter

The basic idea is to have RGB LED strips that are controllable via TCP/IP from a master host and avoid things like DMX512.

I picked up a bunch of RGB WS2812 strips from china, and a DMX512 USB adapter with a controller to run RGB strips, just to see how it worked. It was terrible, even for a wired connection, DMX itself is a really poor protocol and it was super slow pushing it all the data to the strips.

It does support the other types of LED strips too, 400/800khz and 2811/2812 it's based upon the component in this project

http://www.element14.com/community/thread/27131/l/psoc-4-pioneer-kit-community-project100-psoc-4-times-square-led-billboard

Also here is a link to Mark Hastings original project (way back in 2011)

http://www.cypress.com/?rID=57336

So i started to look for alternatives, I looked at all the various CPU options to drive the chips, lots of people complained about timing issues, or tight loops and so on and I wanted to keep costs per node down a bit, so initially i figured use an STM32 and just throw MHZ at the issue, that way i could run effects and stream in.

Then I picked up the nRF+ chips everyone uses and figured i'd build up nodes of those with controllers/repeaters etc. Just as I'd ordered them Hackaday showed the ESP8266 off, so immediately I ordered a box of them.

Just before Hackaday's 10th anniversary, I was looking for ARM chips that were cheap, and digikey had an offer on some at $1 so i bought all of their stock, but then I saw the $4 Cypress PSOC http://www.cypress.com/?rID=92146 , i have loads of dev boards, so i grabbed 10 of them to add to my infamous drawer, which is now about 4 sets of drawers by now.

After poking around with it , I then found a project by a Cypress Engineer who'd implemented the WS2811 protocol as a component on the PSOC5 , I grabbed one of the new boards and the code and started to make a few small changes, then it complained about not enough UDBs, after looking I saw that there are two versions of that dev board, the 41 and 42 , the 41 has no UDBs the 42 does, and of course i'd just ordered the 41's. So I bought a bunch of the chips (since that is the only change ) and new dev boards, but then I ended up giving away most of the 41's to people at the HAD event.

So once i had the 42 variant, wired it up, added a few routines and let the wifi have hers with a strip , so she could code up her own routines.

The Cypress version only supports RGB, RGB is not suited for fancy colour effects , fading and tweening etc. Most colour models are fairly math intensive on the conversions, so i opted to use HSV/HSL which isn't as good as say Lab CIE but works just fine when you are crossfading colours and so on. Which gave me this


This is running from the PSOC , all the fades and so on are generated on chip.

So next was adding the WIFI version, I wired up the ESP8288 added the bi directional level converters on the RX/TX/CH_PD lines, and a LD1117-3.3v , that is what i had at hand.

In cypress creator i added a second UART, configured it for 115kbps 8n1 and wrote a simple echo to the main UART back to the host, loaded up a serial terminal software and tested the chip, I forgot the CH 3.3v tie up the first time, so added that and the chip booted up, once i'd figured out that the chip wants all caps with \r I added it to our wifi network and pinged it, worked. Then i found out it remembers that setting after a reboot, something i'd hadn't known about before.

Next I setup a UDP listening cip and wrote a simple app to send out 450 bytes of data (150 leds 8 bits per RGB. so 150*3) and it worked, so far so good. I had the Frankenstein's monster version of the board.


Then I immediately decided to make a PCB in Eagle and cut it out, for some reason.


That is pretty much all i'd need (at the moment ) so after that was laid out, i decided that i should probably remove the clip on jumpers and just solder in permanent wires instead, just in case it got knocked over or a fly flew past and they popped off.

So i took off the...

Read more »

  • 1 × Cypress PSOC CY8CKIT-049-42xx Must be the 42 version
  • 1 × ESP8266
  • 1 × 3v to 5v logic level convertor, doesn't need to be bi directional
  • 1 × 5V to 3.3V VREG LD117 or better , must provide 3.3V@300mA (needs to be better if 5V powered)
  • 1 × WS2812 RGB LED Strip I used the 30 per metre strip, the 2812 is the one with the IC built in, but you can use the others.

  • left one of the controllers and strips outside for almost a year

    charliex10/18/2015 at 19:44 0 comments

    not completely waterproof , controller, wifi and strips still work fine. cleaning it up and doing a conformal coating on it.

  • 3.3v version, logic level shifter woes.

    charliex01/03/2015 at 06:13 0 comments

    The old BS138 bi directional logic level shifter can't hack 800khz., 400khz is fine, the 10K's make it too slow.

    time for a M74VHC1GT125DF2G

  • Moar videos

    charliex12/27/2014 at 02:09 1 comment

    just like Christmas music, more than once is too often. testing at 921600 kbaud, strips are ordered and acting as one giant contigous strip now.

  • Very silly MFC app added to github

    charliex12/25/2014 at 06:07 0 comments

    I knocked up a very hacky quick app that displays the LED's as buttons and sets the colours to match the LEDS ( within reasons)

    It's expecting broadcast UDP (which is terrible idea) and abuses the OnPaint of MFC, but it's mildly interesting. VS2013 project file,.

    Also helps to show the latency of UDP broadcast around a network.

  • Changing firmware of ESP8266 and other stuff

    charliex12/25/2014 at 01:54 0 comments

    I finally got around to compiling up the ESP8266 firmware on windows, i'd previously setup an EC2 instance beforehand and got it compiling but not tested it.

    I used CHERTS setup here , which actually seemed to work as documented! amazing stuff :)

    http://www.esp8266.com/viewtopic.php?f=9&t=820

    Once i'd fiddled around with python adding all the extra stuff it needs, and gave up on the cygwin version of esptool.

    Compiled new firmware and was left with the at_v0.20 9,3 sdk and firmware files

    C:\Espressif\examples\at_v0.20_on_SDKv0.9.3\firmware

    12/24/2014 17:18 35,120 0x00000.bin
    12/24/2014 17:18 160,992 0x40000.bin

    ok grab https://github.com/themadinventor/esptool setup python with serial support etc.

    quick batch file name it flash.bat and use flash COM4 (or whatever yours is)

    c:\esptool-master\esptool.py --port %1 write_flash 0x00000 0x00000.bin
    pause reset the esp
    c:\esptool-master\esptool.py --port %1 write_flash 0x40000 0x40000.bin

    These last two are only needed if you want to reset the settings.

    pause reset the esp
    c:\esptool-master\esptool.py --port %1 write_flash 0x7C000 C:\Espressif\ESP8266_SDK\bin\esp_init_data_default.bin
    pause reset the esp
    c:\esptool-master\esptool.py --port %1 write_flash 0x7E000 C:\Espressif\ESP8266_SDK\bin\blank.bin

    Connect to a 3.3V UART, ground GPIO 0 , reset the ESP , flash each section, resetting in between.

    in user_main.c i changed the UART setup too :-

    uart_init(BIT_RATE_921600, BIT_RATE_115200);

    then flashed up the image and got it running at 921600 baud, a few false starts but the reset settings above, will help you. It also loses the CIOBAUD command, which is easy to add back.

    so then i ran my CIPSERVER with a UDP port as usual, and nada. . so reflashed back and forth, the usual head scratching and eventually figured look at the code in the firmware, sure enough in at-ipCmd.c UDP listener is commented out. look for and start un-commenting here

      // pUdpServer = (struct espconn *)os_zalloc(sizeof(struct espconn));
    then that whole section is commented out (not sure why lines of // vs #if 0), up until, stop un-commenting on the line before this.
    //    pLink[0].pCon->type = ESPCONN_TCP;
    now look for this, which is also commented out ( i don't know if eclipse has a vertical select like VS does, and frankly i don't want too )
    at_udpserver_recv(void *arg, char *pusrdata, unsigned short len)
    Keep an eye on this routine, since this is why i'm doing the firmware updates anyway.

    Recompile and re-flash, and you ought to be back in business with UDP.

    also in at_cmd.c i modified line 150 to stop compiler noise

        else if(((*pAtRcvData >= '0') && (*pAtRcvData <= '9') )|| (*pAtRcvData == '='))

    Finally in PSoC creator, change the baud rate for the XMAS lights on the WIFI UART thusly

    Re-flash the PSoC light node and test !

    So at first sight the LED's do seem smoother at this baudrate, but that's entirely subjective and the limiting factor maybe elsewhere, its also been a long week ;) but lets call it a win win all around

    update: I put one of the new code nodes up along with the old ones, and its significantly faster..

    The reason i want to redo the code in the firmware is to get rid of the +IPD,0,length:, and any trailing data, from the CIPSERVER, since i'm looking at something that requires the data to have nothing extra added. While its useful in a lot of places, i can do without it here.

    Also i'd like to note back on that long week thing, sometimes you look for something, say the protocol for a bootloader and you expect the OEM not to give it to you, so you poke around and find DLL's that look interesting, then spend a couple of hours completely reverse engineering them back to working C code , then look for API call documentation to give it that extra va-voom and you then discover that in fact they did give you the code for a different version of the bootloader that has got enough info.. The moral of the story is that i'm a pretty awesome RE'r and got the RE'd code back to pretty much the supplied code, and that sometimes maybe you should look...

    Read more »

  • Simple OSX/linux udp

    charliex12/24/2014 at 17:33 0 comments

    only a few small changes from windows version. instructions same for both linux and OSX, assuming gcc is installed already etc.
    
    save as test.c, compile with 
    gcc -std=c99 test.c
    run as 
    ./a.out
    
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <termios.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/time.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    
    // Defines
    #define LIGHTS        "192.168.1.230"    // Address of Node
    #define BUFLEN        ( 450  )            // Length of data to send to LED strips, 150 LEDs, three byte values per LED , 450
    #define PORT        (40002)                // The port the ESP is listening on
    
    void changemode(int dir);
    
    // short cut exit routine
    void die(const char *str)
    {
        fprintf(stderr, "error: %s\n",str);
    
        changemode(0);
    
        // exit with error
        exit(1);
    }
    
    void changemode(int dir)
    {
      static struct termios oldt, newt;
    
      if ( dir == 1 )
      {
        tcgetattr( STDIN_FILENO, &oldt);
        newt = oldt;
        newt.c_lflag &= ~( ICANON | ECHO );
        tcsetattr( STDIN_FILENO, TCSANOW, &newt);
      }
      else
        tcsetattr( STDIN_FILENO, TCSANOW, &oldt);
    }
    
    int _kbhit (void)
    {
      struct timeval tv;
      fd_set rdfs;
    
      tv.tv_sec = 0;
      tv.tv_usec = 0;
    
      FD_ZERO(&rdfs);
      FD_SET (STDIN_FILENO, &rdfs);
    
      select(STDIN_FILENO+1, &rdfs, NULL, NULL, &tv);
      return FD_ISSET(STDIN_FILENO, &rdfs);
    
    }
    
    
    int main(void)
    {
        struct sockaddr_in si_other;
        int s, slen = sizeof(si_other);
        unsigned char data[BUFLEN];
    
        if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
            die("socket create error");
        }
    
        // setup the target port/address
        memset((char *)&si_other, 0, sizeof(si_other));
        si_other.sin_family = AF_INET;
        si_other.sin_port = htons(PORT);
        si_other.sin_addr.s_addr=inet_addr( LIGHTS );
    
        printf("press space to stop\n");
    
        changemode(1);
        // wait for a key press
        while (!_kbhit()) {
    
            // fill the buffer with a simple green fade
                    // each LED is three bytes, RGB, so the 2nd led is (index*3)
            for (int i = 0; i < BUFLEN; i+=3) {
    
                data[i  ] = 0;        // red
                data[i+1] = i>>1;        // green
                data[i+2] = 0;    // blue
            }
    
            // send to ESP
            if (sendto(s, (const char*)data, BUFLEN, 0, (struct sockaddr *) &si_other, slen) == -1) {
                die("couldn't sendto");
            }
        }
    
        //get rid of keypress (fflush)
        getchar();
        changemode(0);
    
        close(s);
    
        return 0;
    }
    

  • Simple windows UDP send

    charliex12/24/2014 at 17:09 0 comments

    Here is a very basic UDP send to one node at a time. Make a simple win32 project and copy this in. (Also added to github)
    
    // simple_udp.cpp : Defines the entry point for the console application.
    //
    
    // Headers (put this in stdafx.h if using precompiled headers)
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    #include <winsock2.h>
    #include <Ws2tcpip.h>
    
    #include <conio.h>
    
    // Library needed
    #pragma comment(lib, "Ws2_32.lib")
    
    // Defines
    #define LIGHTS        L"192.168.1.230"    // Address of Node
    #define BUFLEN        ( 450  )            // Length of data to send to LED strips, 150 LEDs, three byte values per LED , 450
    #define PORT        (40002)                // The port the ESP is listening on
    
    
    // short cut exit routine
    void die(const char *str)
    {
        fprintf(stderr, "error: %s\n",str);
    
        WSACleanup();
    
        // exit with error
        exit(1);
    }
    
    int main(void)
    {
        WSADATA  w ;
    
        struct sockaddr_in si_other;
        int s, slen = sizeof(si_other);
        unsigned char data[BUFLEN];
    
        /* Open windows connection */
        if (WSAStartup(MAKEWORD(2, 2), &w) != 0) {
            fprintf(stderr, "could not initialise winsock\n");
            exit(0);
        }
    
        // create a udp socket
        if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
            die("socket create error");
        }
    
        // setup the target port/address
        memset((char *)&si_other, 0, sizeof(si_other));
        si_other.sin_family = AF_INET;
        si_other.sin_port = htons(PORT);
    
    
        // convert IP address string to numerical
        if (1 != InetPton(AF_INET, LIGHTS, &si_other.sin_addr)) {
    
            die("InetPton failed");
    
        }
    
        printf("press space to stop\n");
    
        // wait for a key press
        while (!_kbhit()) {
    
            // fill the buffer with a simple blue fade
                    // each LED is three bytes, RGB, so the 2nd led is (index*3)
            for (int i = 0; i < BUFLEN; i+=3) {
    
                data[i  ] = 0;        // red
                data[i+1] = 0;        // green
                data[i+2] = i>>1;    // blue
            }
    
            // send to ESP
            if (sendto(s, (const char*)data, BUFLEN, MSG_DONTROUTE, (struct sockaddr *) &si_other, slen) == -1) {
                die("couldn't sendto");
            }
        }
    
        //get rid of keypress (fflush)
        _getch();
    
        closesocket(s);
    
        WSACleanup();
    
        return 0;
    }

  • pushed firmware source code to github

    charliex12/23/2014 at 18:09 0 comments

    The firmware for the PSOC4 + esp8266 is up on github. You can use the Cypress board to test it, P1.5 is the LED output.

    Details are in the eagle file and the firmware schematic in Cypress Creator Project.

    Cliff notes.

    P3.2 connect via buffer to CH_PD
    P3.0 WIFI RX
    P3.1 WIFI TX
    P0.7 Boot Switch
    P1.5 LED strip
    P1.6 Status LED

    You should either run the PSOC+ESP8266 and logic level to 5V for the led strip, or logic levels between the esp and PSOC , i have run the ESP at 5V IO with 3.3V power, for weeks (accidentally) but i guarantee your only ESP8266 that took 6 weeks to ship will immediately explode if you try that.

    I did move some of the lines around in eagle, so they wouldn't conflict with the debug pins, since its an active repo they can get out of sync. So verify against schematic in Creator 3.0

    Preset the BAUD rate of the ESP8266 to 460800 with AT command AT+CIOBAUD=460800

    This baud rate is set in the XMAS Lights TopDesign, double click the uWIFI tab to see it, changing it there requires a change to the ESP8266 BAUD rate as well, use the echo_mode() function in the firmware for a passthru, if using the $4 cypress board, it'll appear at 115200 baud on the its serial port when plugged into a PC. The Two UARTs have independent speeds.

    Edit the run_server() for your WIFI's AP name and password too..

    You can use the Cypress UART Bootloader (Tools/BootLoader Host 115Kbps) or a minipro etc to load this firmware.

    All you have to do is send 450 bytes of UDP to the ESP and the LEDS will display it. I'll add PC code next. You can send to specific IP or broadcast UDP (not recommended for WIFI) use UDP port 40002

    esp8266 rx > tx, tx -> rx, , p3.2 to CH_PD via logic level converter. LED strip directly to P1.5 , all grounds common.

    It's all a little rushed, so i may have missed something out.

  • Started install, programming adapter

    charliex12/07/2014 at 17:01 0 comments

    So i can quickly reflash and diagnose the ESP8266's I made a simple adapter from a 2x4 IDC/ribbon plus a USB to UART adapter that i had lying around.

    The pin sticking out the side is for grounding for GPIO0 to reflash it , or reset, super basic. Just needs 3V3, GND TXD/RXD

    krs built all the rest of the boards, i'd put the chips on so i could flash them , the PSOC's need no supporting hardware to be flashed.

    i have a bunch of PSU's from all electronics, $9 each. I have a large 5V power supply to power everything, but haven't put the base cabling in yet, so these are my cheat's and they've been working on a test load for about a month.

    I mounted it at a slight offset, i did rotate this board design so the esp8266 adapter points away from the board, but range has been fine with this setup and it meant i can fit them into those small pots, i was going to do the usual PVC pipe plus endcaps, but i wanted to see the led's and the boards.

    Also from all electronics i had a bunch of these containers for holding SMD parts etc. I used the hot melt gun to seal off the ingress.

    Side ingress was neater, but i realised it was easier to take them out for any reflashing or so on , i haven't finished the OTA PSOC reflash yet.

    Started to get them all assembled. About half of them done.


    GUI

  • Some pictures

    charliex12/03/2014 at 20:53 0 comments


    (On rev2 i flipped the connector so the wifi points away from the board.) but i like the compact design, and it doesn't seem to affect range.

    One node streaming with mostly full data change per frame.

View all 22 project logs

  • 1
    Step 1

    Use P3_0 and P3_1 to communicate with the ESP8266 RX/TX via a 5v<>3.3v shifter., add UART component and config to 11500kbps, 1024 rx buffer, 128 tx buffer (or less) default everything else.

    Add a X to 3.3V VREG and power the ESP8266 and level shifter.

    Make CH_PD high.

    I'll publish all the code and doc's after i've made sure it's right. so far its been running for about 14 hours straight.

    Uploaded schematic on github, my first github commit. i still like svn ;)


View all instructions

Enjoy this project?

Share

Discussions

Maxwell wrote 10/03/2018 at 18:10 point

Hey Charlie, Any chance you can upload the PSoC Creator Project file on this?

  Are you sure? yes | no

pushkar.b wrote 02/13/2017 at 05:58 point

Hello. A comment to check out your project on my cypress forum question got me here. We're currently working on our final year project using a PSOC 4 BLE and we have sorted out our whitelist but now we need to update timestamps and phone address via the ESP8266 module via IoT. It would be of great help if you could share with us the code you used to get your project done so we could get a rough idea.

  Are you sure? yes | no

Ben Delarre wrote 11/07/2014 at 01:04 point
Looking good Charlie! We'll have to meet up about this sometime...there might be an opportunity to use this for lighting the new hackerspace...

  Are you sure? yes | no

charliex wrote 11/07/2014 at 01:41 point
you guys should come out and hang with us next BBQ or party. Next get together i'll send you an note. krs does a crafternoon thing as well with the women hackers too, next one is early dec i think.

  Are you sure? yes | no

Ben Delarre wrote 11/08/2014 at 15:24 point
Sounds great. We'll be back mid November so that's good timing.

  Are you sure? yes | no

charliex wrote 11/08/2014 at 19:03 point
cool

  Are you sure? yes | no

Ben Delarre wrote 10/27/2014 at 19:02 point
Hey Charlie. At the HAD event, you mentioned some sort of beast of a power supply you were going to use for the 100 meters of LED madness you intend to build. I still can't wrap my head around what you were saying this thing could do. Any chance you could write up some details of what it is and how it works?

  Are you sure? yes | no

charliex wrote 10/27/2014 at 19:25 point
Sure thing, its a 5V 240 AMP, yes amps, yes 240,, server power supply, with PFC. I'll dig up the details on it.

  Are you sure? yes | no

Ben Delarre wrote 10/27/2014 at 19:35 point
Had to go look up PFC....so I guess that protects your house circuit breakers from tripping every time you flash to full white on 6000 leds? :-)

  Are you sure? yes | no

charliex wrote 10/27/2014 at 20:01 point
if you don't at least trip one breaker during XMAS lights, you're not giving it the full clark griswald

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates