Monthly Archives: March 2015

The Problem with Ports ESP8266

 

I was about to write about my stunning success with the ESP8266 and WS2812b chips when I’ve hit a snag.

I have a working example of high speed port bashing to control the serial LEDS on GPIO-0.. but I want to use GPIO12. Assuming all of the ports are setup properly..

WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR + GPIO_ID_PIN(0), 1 );

WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR + GPIO_ID_PIN(0), 0 );

The above toggles GPIO-0 up and down at high speed.

WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR + GPIO_ID_PIN(12), 1 );

WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR + GPIO_ID_PIN(12), 0 );

The above does not work on GPIO-12

WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR + GPIO_ID_PIN(12), 0x1000 );

WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR + GPIO_ID_PIN(12), 0 );

The above does not work on GPIO-12 either

WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR,0x1000 );

WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR,0 );

The above works a TREAT on GPIO-12 – but sadly it also messes up the OTHER port bits!!!!

What is the correct code for GPIO-12 ???

Facebooktwittergoogle_pluspinterestlinkedin

C ? Construct

For the LIFE of me I do not know why this statement is failing.  There are two versions of settings for port outputs here – the one in red and the one in blue. If I choose the blue version it will only work in one direction, not the other.

If I choose the version in red – it works full stop.

The same ? construct is used in sending messages out and that works perfectly. This is C programming in Eclipse for the ESP8266 chips… “intvalue” is just the number 0 or 1

 

else if (strcmp(token,"out2")==0)
        {
            if (sysCfg.out_4_status!=intvalue) { sysCfg.out_4_status=intvalue; do_update=1; } // only update if actual change

            if (sysCfg.out_4_status==1) GPIO_OUTPUT_SET(LED_GPIO_4, OUT_ON); // on or off by default
            else GPIO_OUTPUT_SET(LED_GPIO_4, OUT_OFF);

            //GPIO_OUTPUT_SET(LED_GPIO_4, (sysCfg.out_4_status==1) ? OUT_ON : OUT_OFF); // doesnt work - don't know why
            strcpy(token,tBuf); strcat(token,"/out2"); MQTT_Publish(client, token,(sysCfg.out_4_status==0) ? "OFF" : "ON" ,(sysCfg.out_4_status==0) ? 3 : 2, 0, 0);
        }

Thoughts anyone? I must’ve been starting at this for too long.

Facebooktwittergoogle_pluspinterestlinkedin

MongoDB on the Pi

MongoDBI’m busy compiling MongoDB for the Pi and it’s going to take hours apparently – so I figured I’d give you some updates while I’m waiting.

I’ve made some progress with my little ESP8266 board (ESP-12) in terms of deciding how to handle MQTT.  Initially I had a bunch of subscribes to various topics and at some point it hit me.. really, you only need 2… one with your ID (whatever you choose to use) for messages coming in specifically to that one board – and another which does not have an ID attached – i.e. a sort of global incoming message.  The actual message content than then therefore decide what actually happens.  In my case I might want to get the temperature, or turn an output on – or even pass on a message to an Arduino via the serial port.  I’ve done this by coming up with a simple message format not a million miles away from JSON (don’t any purists start on me).  By taking in the message then looping through – I can do several things at once.

So for example lets say this particular ESP8266 unit is ID 999.  I send a message from say the PI to 999/to_esp and the content might be {out1:1;temperature:;ext:”rgb:red=255,green=5,blue=50”}

Let’s break that down… so the first instruction is out1:1; which turns output 1 (GPIO0 on). As it happens I also have it send a message back to confirm that status. The next thing is temperature:; You’ll notice there is no argument there – and that is a request to return the temperature in an MQTT message – which it does. The third item is this.. ext:”rgb:red=255,green=5,blue=50” which does not need a semicolon as it’s the last item in the list… what that says is – here’s an external command to pass to the serial port so that, say an Arduino can handle it.

So what goes out of the serial port after a little dressing is… {rgb:red=255,green=5,blue=50} and I’ve already written the Arduino code to watch for a package coming in the serial line and acting accordingly; In this case it will start a series of high speed pulses out to a port bit to control a 5v serial LED strip WS2812b ….it can do a nice soft fade as it is not taking up any of the ESP8266’s time.

Had I sent the version of the command to the board with no ID, the result would be the same but no return messages would be sent – so that means you can with one command turn everything on or off no matter how many little ESP8266s you have.

NoSQLSo that’s nice but what does it have to do with MongoDB? Well (still compiling and will be for hours – if you want to have a go try this link but don’t blame me if it does not work as I’ve not tested it yet) – I watched a Node-Red demonstration and the guy was using MongoDB which is a “NoSQL” database which basically works on keys – and one of the more notable aspects was that you don’t have to go defining tables etc., you just give it a name for the data you want to store – and store it  - that seemed eminently civilised and so I figured I’d install it on the Pi (a Pi-specific version in the link) – and so with warnings that it will take several hours – that’s what I’m doing. 

I’m constantly amazed at how these very long and involved loading and compilations actually work – I’m always waiting for something to go wrong..

Still standing by my original comments re: ESP boards.. score ESP-12 10, ESP201 0.

More later when the Pi actually does something other than sitting looking busy.

Update: An hour later, accidentally pulled the plug on the Pi – had to start again…… 2 hours later – after many, many warnings but no errors, lots of “deprecated” messages but the install looks to be done.. just some housekeeping to do… late evening:  It works – considering the number of warnings I had my doubts but the mongo connectors in Node Red are working.

Facebooktwittergoogle_pluspinterestlinkedin

ESP201

Many thanks to readers in here for the comments – I can’t believe how keen people are to help. Ok, so you may recall that some time ago I bought an ESP-201 board and the baseboard to with it – the whole lot was about a tenner on Ebay, a marvellous opportunity to play with the ESP8266 while accessing all the pins AND on a 0.1” pin centre basis – easy for prototyping.

ESP201Well, it didn’t work out that way, the whole package came with zero documentation and frankly the sensitivity of the aerial was ATTROCIOUS or so it seemed. I’ve had feedback from a couple of you and so this morning I decided to go take a look with my new microscope (another Ebay special).

So what did I find? Well, sure enough – look at the board on the right – the centre part is the little ESP201 board itself. See the aerial – see the little link on the right? See the or SMT resistor to the left of it? Does that look like there’s a track going from the chip to the aerial?

No, you’re right – it DOESN’T – the damned thing is connected to the external aerial!!!

ESP-201Just to exaggerate the point here’s another photo in which (click to zoom the image) you can clearly see that the 0r resistor is designed to offer a choice, horizontally it connects to the internal aerial, vertically (default) it connects to the external aerial – why on EARTH would anyone do that?

I’d given up on this board on the basis (again in the absence of any documentation) that it was just a really bad design. Wouldn’t a link have worked??

I don’t know how many of you have tackled surface mount but let me tell you – if your hands shake – forget it.  If they don’t, you need a nice set of tweezers with a 45 degree end on them. If you apply the iron to one side, the chances are both sides of the 0r resistor soldering will melt and you can lift the part off cleanly, Ensure your iron is hot – and as clean as possible.

ESP-201[6]Anyway, thanks to a nice set of snips and a fine soldering iron… a few moments later… I FREELY admit, moving that resistor was neither the finest hour for me or my cheap Chinese tweezers and as I didn’t have any isopropyl handy it’s a little messy – but ultimately it’s a 2 minute job to change the link over. Actually a blob of solder would have done because a 0r resistor is pretty much just a wire.

Did it make any difference? No – not at all – the unit after blowing the chip powered up and would not connect to the router. With some repositioning, it would – which clearly indicates a sensitivity issue.

ESP-12Frustrated with that I took my sparkly new ESP-7-8-12 baseboard (which has 2 resistors and nothing else, soldered on an ESP-12, wired it (0.1” centres) to my ESP-01 adaptor (the board shown on the left already has a pull-up for CH_PD and a pull-down for GPIO15), blew the chip, turned it on – no problem at all.

I’m beginning to think that life is too short to spend much more time on those EP201 board especially considering the cost of the ESP12s, the fact that they are shielded and that adaptors are so cheap… Next stop – making sense of the A/D so I can use it as a battery voltage indicator.

Facebooktwittergoogle_pluspinterestlinkedin

Webmin for Pi

A friend of mine put me onto this link tonight – a nice web admin panel for the Raspberry Pi… and no I didn’t get around to soldering the ESP-12 module – that’s a writeup for the weekend – and yes, my ESP201 module definitely does NOT have the internal aerial hooked up by default – what WERE they thinking about.

Anyway – check out this link!  It even updates itself once installed!!!

http://c-mobberley.com/wordpress/2014/09/26/webmin-setup-on-raspberry-pi/

While you are on – Nathan Chantrell is using ESP-01 and MQTT in a setup not a million miles away from where I’m heading… see what you think of this – he has code available.. http://nathan.chantrell.net/20141230/wifi-mqtt-display-with-the-esp8266/#comment-334251

Facebooktwittergoogle_pluspinterestlinkedin

Monday Morning at the Lab

Just in case anyone in the UK or EU is even remotely interested, I just put up my little pocket scope on Ebay. http://www.ebay.co.uk/itm/231492939705

Meanwhile talking of Ebay, the Raspberry Pi is currently working a treat on THIS little number…. a cheap WIFI dongle.  http://www.ebay.co.uk/itm/331400872324 -  it’s been running overnight and logging temperatures without a hitch. For under £4 that can’t be bad.  I’m thinking, once I get the Pi and the ESP8266 boards properly communicating over MQTT of putting a display on the Pi and making that the wall unit rather than hiding it away. Well, clearly, I’d rather NOT have to have a network cable going up the wall so the WIFI dongle solves a problem.

my ESP-12 units turned up – still waiting for some little adaptor boards to come that give you 0.1” pitch from the ESP-12s for experimenting.  It seems that it is necessary to ground GPIO-12 as well as taking the PD line high permanently – and I had confirmation yesterday that using GPIO-0 with a ground-based setup (for example an NPN transistor and resistor arrangement is NOT a good idea – personally I’ve been using then to power solid state relays taking the other side of the relay to positive hence ensuring a small amount of positive voltage at power up – and I’ve had no problems.  I plan also to tie GPIO16 to the external reset so I can experiment with the low power sleep mode. All of that late this week when my adaptors arrive.

Oh, I knew there was something else. Has anyone doing C coding with ESP8266s used this yet? Seems like a fine way to mess with ESP8266 GPIOs – giving you a consistent interface to handle GPIO 0,2, 4,5, 12,13 and 14. The author says he HAS used this with SDK 0.9.5 so it is pretty much up to date. As soon as I get my adaptors for the ESP-12s I’ll give it a good thrashing.  https://github.com/eadf/esp8266_easygpio

Facebooktwittergoogle_pluspinterestlinkedin

Raspberry Pi WIFI

Today is going well up to now – I purchased a WIFI dongle for around £4 from EBAY, supposedly specifically for Pi (yeah right) market simply “802.11n”.  Plugged it in, rebooted the Pi 2, nothing.  I scoured the web and discovered you can look to see what’s happening with:

dmesg | more

which shows installed items one page at a time (Spacebar) and sure enough in there was the 802.11 device with a driver missing – looked like a Realtek driver. I went off looking for the name and one of the very first Google responses (sorry I didn’t keep the link) showed a rather long SUDO WGET command to go get the very driver (rtl8188eufw.bin)  - did that, reboot – one working WIFI.

So now my little Pi2 has only ONE wire going to it – the power lead from the little solar/usb charger I’m using for battery backup.

I make no suggestion this will help but if you find yourself missing this driver this is what I did in the Pi2 terminal window (then rebooted) – no breaks…

sudo wget https://github.com/lwfinger/rtl8188eu/raw/c83976d1dfb4793893158461430261562b3a5bf0/rtl8188eufw.bin -O /lib/firmware/rtlwifi/rtl8188eufw.bin

 

I then went off and tied the IP address and MAC together in my router and that’s me one wire down.

Facebooktwittergoogle_pluspinterestlinkedin