-
1get required software
I assume you are familiar with the Arduino IDE and have it installed on your PC.
Download CCLib from
https://github.com/kirovilya/CCLibThis is the firmware for your custom, ESP8266 based programmer
Download CC2531 Firmware
You can use either
or
https://raw.githubusercontent.com/kirovilya/files/master/CC2531ZNP-Pro-Secure_LinkKeyJoin_mod.hex
On Linux, you can simply download it by typing
wget https://raw.githubusercontent.com/kirovilya/files/master/CC2531ZNP-Pro-Secure_LinkKeyJoin_mod.hex
I installed and verified both versions to be working. Hence I have attached them to this project.
If you download the CC2531ZNP-Prod.hex from here (hackaday.io) you do not have to modify the file!
Important note:
When using the arduino based CCLib_proxy debugger/programmer as described here, the custom firmware (CC2531ZNP-Prod_20181119.zip) from Koen Kanters, has to be modified. Otherwise you will not be able to flash it!
The modification is really simple:
Unzip the archive and open the .hex file in a text editor of your choice.
Scroll to the very bottom of the file and remove the second line from the bottom. In the .hex file above, the according line is
:0400000500002D6F5B
Just save the file and you are good to go.
You will also need Python 2.7 or later installed to your system.
Once you've downloaded/unzipped CCLib, open a terminal and change directory into the Python folder
cd CCLib/Python/
Now, install the required python modules by typing:
pip install -r requirements.txt
-
2Prepare your wemos d1 mini board
Install the
Arduino/CCLib
library to your arduino IDEOpen the CCLib_proxy.ino from CCLib/Arduino/CCLib/Examples/CCLib_proxy
I have uploaded my modified version of the arduino sketch to hackaday.io.
If you have downloaded the CCLib_proxy.ino linked above you can skip the following code modification.Modify the code:
Specify the correct Pins for the ESP8266 / Wemos D1 mini
This is important, since it makes a big difference which Pins you use! I was not able to make the programmer work when I initially used other pins. After more than an hour experimenting I found this configuration to be working flawlessly out of the box.
See approx. line 37
// Pinout configuration (Configured for wemos D1 mini) int CC_RST = D5; int CC_DC = D7; int CC_DD_I = D6; int CC_DD_O = D4;
Then, look for the first delay() at approx. line 98 and increase the initial value (50) to 1000:Again. this is needed for the ESP8266 / wemos d1 mini / nodeMCU to get it working
at approx. line 98:
// Wait for chip to initialize delay(1000);
When using an arduino uno/nano/... you probably don't have to change the delay.
Once you have modified the code, compile and upload it.
-
3Connect your CC2531 Adapter
Once you've compiled and uploaded the CCLib_proxy to your wemos d1 mini board, unplug it from the USB bus.
Now, get some (actually 5) jumper wires and connect your ESP board to the debug port of your CC2531 adapter. Since the ESP uses 3.3v, you don't need a voltage divider!
Please note:
In contrast to your common breadboard / connector, the debug port on the CC2531 has a smaller spacing of 1mm. In order to connect your wires, you can either use the linked Debugger Cable or carefully connect your SMD probes to the tiny pins. I've seen a couple of people destroy their debug port / breaking pins by handling it too rough. These small pins are really pretty fragile! So take care when not using the small spaced connector cable.
Note, that on the wemos/ESP side, D6 ( DD_I ) and D4 ( DD_O ) are connected together and go to Pin 4 ( DD / Debug Data ) on the CC2531 debug port.
You only need to connect these four Pins on the CC2531:
1 - GND
3 - DC (Debug Clock)
4 - DD (Debug Data)
7 - Reset
If the stick lies in front of you, the USB-Port facing to the left, Pin 1 is the one on the top right of the 10 Pin programming header.
-
4Verify proper communication with your CC2531 USB Adapter
Verify your connections and plug the ESP board / wemos d1 mini to your USB port.
Make sure the CC2531 Stick is not plugged into an USB port yet!
Now, find out which device it gets assigned.
On linux, this can be done e.g. by typing 'dmesg'. Look for something like
...
[614271.856268] usb 2-2: ch341-uart converter now attached to ttyUSB0
On windows, use the appropriate COMx Port.
Once you know your serial port (e.g. /dev/ttyUSB0), go to the CCLib/Python folder.
cd CCLib/Python
Plug your CC2531 to another free USB port (or use a power bank or a USB-Charger)
Now see if you get some details about your device by typing (adjust serial port accordingly)
python cc_info.py -p /dev/ttyUSB0
sometimes it might be necessary to add the -E option to the above command:
python cc_info.py -E -p /dev/ttyUSB0
Option -E,--enter Enter debug mode if not debugging already
The -E option helps to bring the CC2531 to debug mode.
If everything is working, you should get a reply similar to this one:
$ ./cc_info.py -E -p /dev/ttyUSB0 INFO: Found a CC2531 chip on ttyUSB0 Chip information: Chip ID : 0xb524 Flash size : 256 Kb Page size : 2 Kb SRAM size : 8 Kb USB : Yes Device information: IEEE Address : 00124b0014aa PC : 0000 Debug status: [ ] CHIP_ERASE_BUSY [ ] PCON_IDLE [X] CPU_HALTED [ ] PM_ACTIVE [ ] HALT_STATUS [ ] DEBUG_LOCKED [X] OSCILLATOR_STABLE [ ] STACK_OVERFLOW Debug config: [ ] SOFT_POWER_MODE [ ] TIMERS_OFF [X] DMA_PAUSE [X] TIMER_SUSPEND
If you get some sort of error instead, try again.
This time, unplug both devices from their USB-Ports.
Type the cc_info.py command as above but do not press enter yet.
Now, connect your ESP board to your USB port.
Connect the CC2531 Stick to another USB port.
Hit enter on your keyboard to execute the previously typed command.
Once you've succeeded, you can flash the new firmware as described in the next step.
-
5Flashing custom ZigBee Firmware
If you have verified that your programmer can communicate with your cc2531 adapter (see above step) you can flash your device.
Assuming you have your firmware image (the .hex file) in the same folder as your python scripts (in CCLib/Python/ ) you can start the programming by typing
python cc_write_flash.py -e -p /dev/ttyUSB0 --in=CC2531ZNP-Pro-Secure_LinkKeyJoin_mod.hex
or, when using the modified firmware from Koen Kanters
python cc_write_flash.py -e -p /dev/ttyUSB0 --in=CC2531ZNP-Prod.hex
If everything works out, it should look like this:
python cc_write_flash.py -e -p /dev/ttyUSB0 --in=CC2531ZNP-Pro-Secure_LinkKeyJoin_mod.hex INFO: Found a CC2531 chip on ttyUSB0 Chip information: Chip ID : 0xb524 Flash size : 256 Kb Page size : 2 Kb SRAM size : 8 Kb USB : Yes Sections in CC2531ZNP-Pro-Secure_LinkKeyJoin_mod.hex: Addr. Size -------- ------------- 0x0000 8176 B 0x1ff6 10 B 0x3fff0 1 B 0x2000 239616 B This is going to ERASE and REPROGRAM the chip. Are you sure? : y Flashing: - Chip erase... - Flashing 4 memory blocks... -> 0x0000 : 8176 bytes Progress 100%... OK -> 0x1ff6 : 10 bytes Progress 100%... OK -> 0x3fff0 : 1 bytes Progress 100%... OK -> 0x2000 : 239616 bytes Progress 100%... OK Completed
Important note:
Programming takes pretty long ( up to two hours ) to finish. So don't worry!
Just make sure that you don't disconnect your wires accidentally while programming is in progress!
-
6Use with home automation software as desired
Once your Adapter is flashed, just plug it into the device running your home automation system, e.g. iobroker, domoticz, home assistant / hass.io or openhab.
In iobroker, install the ZigBee-Adapter, configure serial port and start pairing your devices.
Alternativelly, use the ZigBee2MQTT gateway to place your adapter at a remote location:
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
Hi! Thanks for this tutorial. Does it work on Windows and with a WeMos D1 (not mini)? I am still learning all this...
Are you sure? yes | no
got error like error: 'D5' was not declared in this scope
Are you sure? yes | no