How to select a CC2530 board
Ebay and Aliexpress offer several boards with the CC2530 chip (keyword: CC2530). You may select any board, but use the following criteria:
- The board must have the CC2530F256 chip (fig. 3). The key number here is 256 and it means 256 KB of flash memory. Most firmware was compiled for 256K memory.
- The board may have many pins or contacts. If you do not have a soldering iron then select a board with headers. I would suggest to select a board where each pin has the corresponding label. The label may slightly different on different boards: P0.2, P02, P0_2 are the same pin. The board must have at least the following pins:
- Po.2, Po.3, P2.0 – used for a UART interface. If you plan to use this board instead CC2531 and connect to your SBC like Raspberry Pi, then you need these pins. If you’ll upload a router firmware to this board then these pins are optional.
- P2.1, P2.2, RST – used for uploading firmware.
- GND – ground.
- Power source (VCC) – it may be 3.3V, 5V or both. This pin can be marked by VCC only. Internally, the CC2530 chip uses the 3.3V voltage, but a manufacturer may add a voltage regulator on the board and you may use any supported voltage (3.3V or 5V, no difference). Please, read a description for this board carefully about the voltage.
- The board may include an additional small chip (fig.5). Most likely, this is a wireless signal amplifier. Usually these boards contain “Long range”, “RF front-end”, “RF amplifier”, “CC2591”, “RXF2401” in a description. These boards require a special firmware. I would suggest to select this board if you really have a firmware for this combination of the main chip (CC2530) and the RF front-end chip.
- The board may contain an antenna on-board (fig.2, 3, 6) or a connector for an external antenna (fig. 1, 3, 4, 5). The board with an external antenna will work better in most cases.
- Some boards may have a metallic shield over the main chip and/or the RF front-end. This shield protects the board from radio noises (good). But I would suggest to buy this board from a trusted vendors only because you cannot be sure about chips under this cover.
- Rare CC2530 based boards may include an USB interface (fig. 6). CC2530 does not have native USB support apart from CC2531. Therefore a manufacturer adds an additional chip on the board. The additional chip implements the USB interface and the CC debugger. Therefore you can upload a firmware to this board without a special debugger (CC debugger or SmartRF04EB). Therefore it holds small space on your work table. It can be useful for developers. If you need only one CC2530 or CC2531 for a coordinator role you may save money. Please, read a description for a board carefully because this USB interface and chip may be used for another purpose. Therefore I cannot recommend this board for beginners.
|https://ptvo.info/wp-content/uploads/2018/05/cc2530_2_2-287x300.png 287w" sizes="(max-width: 203px) 100vw, 203px" style="box-sizing: border-box; border: 0px; display: block; margin: 0px auto 5px; max-width: 100%; height: auto; border-radius: 4px;">||Fig. 1 The compact board with an external antenna|
|https://ptvo.info/wp-content/uploads/2018/06/CC2530-2-300x158.png 300w, https://ptvo.info/wp-content/uploads/2018/06/CC2530-2-600x316.png 600w, https://ptvo.info/wp-content/uploads/2018/06/CC2530-2-680x358.png 680w" sizes="(max-width: 245px) 100vw, 245px" style="box-sizing: border-box; border: 0px; display: block; margin: 0px auto 5px; max-width: 100%; height: auto; border-radius: 4px;">||Fig. 2 The board with the internal antenna, place for an external antenna connector and a debug interface header (compatible with the CC debugger cable, the dupont cable is not required)|
|https://ptvo.info/wp-content/uploads/2018/06/CC2530-1-300x249.png 300w" sizes="(max-width: 151px) 100vw, 151px" style="box-sizing: border-box; border: 0px; display: block; margin: 0px auto 5px; max-width: 100%; height: auto; border-radius: 4px;">||Fig. 3 The compact board with the internal ceramic antenna and an external antenna connector|
|https://ptvo.info/wp-content/uploads/2018/06/CC2530-3-300x177.png 300w" sizes="(max-width: 226px) 100vw, 226px" style="box-sizing: border-box; border: 0px; display: block; margin: 0px auto 5px; max-width: 100%; height: auto; border-radius: 4px;">||Fig. 4 The compact board with an external antenna. Black design.|
|https://ptvo.info/wp-content/uploads/2018/06/CC2530-PA-4-300x231.png 300w" sizes="(max-width: 192px) 100vw, 192px" style="box-sizing: border-box; border: 0px; display: block; margin: 0px auto 5px; max-width: 100%; height: auto; border-radius: 4px;">||Fig. 5 The CC2530 board with the RF front-end|
|https://ptvo.info/wp-content/uploads/2018/06/CC2530-5-300x161.png 300w" sizes="(max-width: 272px) 100vw, 272px" style="box-sizing: border-box; border: 0px; display: block; margin: 0px auto 5px; max-width: 100%; height: auto; border-radius: 4px;">||Fig. 6 The CC2530 board with a USB connector and the additional 8051 chip|
Here is an example for the most simple case when all pins are soldered on the board and have labels (fig. 1).
- The CC2530 board.
- The dupont cable (5 wires, female – female).
- The CC-debugger or SmartRF04EB (look very similar).
- The USB cable between the debugger and your computer (it usually comes with the debugger, USB-A <-> USB-mini).
- Computer with Windows.
- Flash Programmer V1 (V2 does not work).
How to connect CC2530 to the debugger
This is simple. Use the dupont cable and connect pins on the debugger’s connector to the corresponding pin on your board.
Note: if CC-debugger cannot detect your board, additionally try to connect the pin #2 to 3.3V.
https://ptvo.info/wp-content/uploads/2018/06/smartrf04eb-pinout-300x165.png 300w" sizes="(max-width: 536px) 100vw, 536px" style="box-sizing: border-box; border: 0px; display: block; margin: 0px auto 5px; max-width: 100%; height: auto; border-radius: 4px;">
https://ptvo.info/wp-content/uploads/2018/06/smartrf04eb_cc2530-215x300.jpg 215w" sizes="(max-width: 265px) 100vw, 265px" style="box-sizing: border-box; border: 0px; display: block; margin: 0px auto 5px; max-width: 100%; height: auto; border-radius: 4px;">
The board from fig. 2 is compatible with a flat white cable usually shipped with CC-debugger or SmartRF04EB. This flat cable can be connected to the yellow header (the red wire should be connected to pin #1 of this header).
https://ptvo.info/wp-content/uploads/2018/06/smartrf04eb-150x150.jpg 150w" sizes="(max-width: 225px) 100vw, 225px" style="box-sizing: border-box; border: 0px; display: block; margin: 0px auto 5px; max-width: 100%; height: auto; border-radius: 4px;">
Note: if your board has the 5V power pin only then you must connect an external power source (5V and GND) to the corresponding pins on your board instead of 3.3V from the debugger. GND of the debugger and the power source must be connected at the same time.
How to connect a CC-debugger to your computer
Connect your debugger to a USB port on your computer using a standard USB cable. A new USB device should appear in Devices Manager on your computer. If you’ve installed Texas Instruments Flash Programmer before, the drivers for the new USB device will be installed automatically. You should see something like “SmartRF04EB” or “CC-debugger” in Devices Manager.
How to select a right firmware
Here are examples for general usage cases. All these examples may have exceptions.
- Select a firmware for the right chip: CC2530 in our case.
- If your board has a RF front-end chip then you must select a firmware for combination of the main chip and the RF chip (for example CC2530 + RXF2401). For example, CC2530ZNP-Pro-Secure_LinkKeyJoin_RXF2401.hex
- Select a firmware for your Zigbee network. Devices with different network parameters are incompatible (they cannot communicate). Each Zignbee network has the following key parameters:
- Network Id (PanId).
- Security key.
- Radio channel number. This requirement is not strict. Many Zigbee devices may scan channels and find the correct channel number. But some Zigbee devices work with the pre-defined channel number only.
- Select a firmware for the device type you want to get from the CC2530 board:
- Coordinator: it should be connected to a computer or SBC (Raspberry Pi, BananaPi, OrangePi, etc), because in most cases it operates under control of a computer. The firmware file name or a description may contain keywords: “coordinator”, “ZNP”. For example, CC2530ZNP-Pro-Secure_LinkKeyJoin.hex. The ZNP firmware is universal, because it operates under control of a computer and it may configure the board as necessary, probably for any Zigbee network.
- Router: it works independently (not linked to a computer) and extends coverage of your Zigbee network. For example, CC2530-router.hex.
You may download my firmware for a Xiaomi coordinator and router here.
How to flash (upload) firmware
Ok. You’ve connected the debugger and the board.
- Start Flash Programmer. Your debugger should be in the list. If the debugger does not appear there try to press the “Reset” button on the debugger.
- Select a firmware file using the “…” button.
- Select the following options.
- Click the “Perform actions” button.
https://ptvo.info/wp-content/uploads/2018/06/flash-programmer-v1-300x262.png 300w, https://ptvo.info/wp-content/uploads/2018/06/flash-programmer-v1-600x524.png 600w, https://ptvo.info/wp-content/uploads/2018/06/flash-programmer-v1-680x594.png 680w" sizes="(max-width: 704px) 100vw, 704px" style="box-sizing: border-box; border: 0px; display: block; margin: 0px auto 5px; max-width: 100%; height: auto; border-radius: 4px;">
Setting up a Zigbee2mqtt gateway
- Flash the Z-Stack coordinator firmware on the Zigbee board
- Install zigbee2mqtt to run on the Raspberry Pi
- Setup a daemon to run zigbee2mqtt
Flash the Z-Stack coordinator firmware on the Zigbee board
Install zigbee2mqtt to run on the Raspberry PiSteps based on
Setup a daemon to run zigbee2mqttbased on zigbee2mqtt - 5. (Optional) Running as a daemon with systemctl
The following is a cheat sheet of some of the more common commands for using a USB drive with a Pi. I've written an extensive tutorial on using USB drives on a Pi shell at http://ipggi.wordpress.com/2013/03/21/u ... pberry-pi/. It covers power supply issues, mounts, performance, disk file formats, compatibility and formating.
To mount a USB drive:
To list your file systems:
Before disconnecting a USB drive:
Format a drive to Linux EXT4
Add Apple OS X HFS+ read/write support
Format a drive to HFS+
Add Windows NTFS read/write support
Format a drive to NTFS
Add Windows/DOS FAT32 read/write support
Format a drive to FAT32
No filesystem could mount root, tried: ext4
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block (179,2)
- sudo fsck.ext4 -fy /dev/sdc2
- need the init file editing to force the HDMI TV o/p.
- I opened (in windows) the SD cards and edited the config.txt file. I added the following line
In this tutorial we show you five ways you can run a program on your Raspberry Pi at startup. The five methods that are available to run a program at boot are:
You can use any program that you want to run at boot; for this tutorial we are using a sample python program which will speak at the startup of Raspberry Pi. This sample program will use the Espeak package to make the Raspberry pispeak “Welcome to the world of Robots”.
If you do not have the Espeak package installed , run the following in terminal to install:
sudo apt-get install espeak
To learn more about how to get the Raspberry Pi speak, we have a tutorial here.
In the /home/pi directory, open a file for editing:
sudo nano sample.py
And enter the following code and save it (press CTRL+X and enter Y ).
#! /usr/bin/env python from subprocess import call call([‘espeak “Welcome to the world of Robots” 2>/dev/null’], shell=True)
https://32414320wji53mwwch1u68ce-wpengine.netdna-ssl.com/wp-content/uploads/2014/11/test.png 628w" sizes="(max-width: 605px) 100vw, 605px" style="height: auto; max-width: 100%; vertical-align: middle; border: 0px;">
Method 1: rc.local
The first method to run a program on your Raspberry Pi at startup is to use the file rc.local. In order to have a command or program run when the Pi boots, you can add commands to the rc.local file. This is especially useful if you want to power up your Pi in headless mode (that is without a connected monitor), and have it run a program without configuration or a manual start.
On your Pi, edit the file /etc/rc.local using the editor of your choice. You must edit it with root permissions:
sudo nano /etc/rc.local
Add commands to execute the python program, preferably using absolute referencing of the file location (complete file path are preferred). Be sure to leave the line exit 0 at the end, then save the file and exit. In nano, to exit, type Ctrl-x, and then Y.
https://32414320wji53mwwch1u68ce-wpengine.netdna-ssl.com/wp-content/uploads/2014/11/test1.png 560w" sizes="(max-width: 608px) 100vw, 608px" style="height: auto; max-width: 100%; vertical-align: middle; border: 0px;">
If your program runs continuously (runs an infinite loop) or is likely not to exit, you must be sure to fork the process by adding an ampersand (“&”) to the end of the command, like:
sudo python /home/pi/sample.py &
The Pi will run this program at bootup, and before other services are started. If you don’t include the ampersand and if your program runs continuously, the Pi will not complete its boot process. The ampersand allows the command to run in a separate process and continue booting with the main process running.
Now reboot the Pi to test it:
Also, be sure to reference absolute file names rather than relative to your home folder. For example use `/home/pi/myscript.py` instead of `myscript.py`.
If you add a script into /etc/rc.local, it is added to the boot sequence. If your code gets stuck then the boot sequence cannot proceed. So be careful as to which code you are trying to run at boot and test the code a couple of times. You can also get the script’s output and error written to a text file (say log.txt) and use it to debug.
sudo python /home/pi/sample.py & > /home/pi/Desktop/log.txt 2>&1
Method 2: .bashrc
The second method to run a program on your Raspberry Pi at startup is to modify the .bashrc file. With the .bashrcmethod, your python program will run on boot and also every time when a new terminal is opened, or when a new SSH connection is made. Put your command at the bottom of ‘/home/pi/.bashrc’. The program can be aborted with ‘ctrl-c’ while it is running!
sudo nano /home/pi/.bashrc
Go to the last line of the script and add:
echo Running at boot sudo python /home/pi/sample.py
The echo statement above is used to show that the commands in .bashrc file are executed on bootup as well as connecting to bash console.
https://32414320wji53mwwch1u68ce-wpengine.netdna-ssl.com/wp-content/uploads/2014/11/test3.png 378w" sizes="(max-width: 496px) 100vw, 496px" style="height: auto; max-width: 100%; vertical-align: middle; border: 0px;">
Now reboot the Pi to hear the Pi speak at startup.
The below image shows that the commands added to .bashrc file get executed even while opening a new terminal.
https://32414320wji53mwwch1u68ce-wpengine.netdna-ssl.com/wp-content/uploads/2014/11/test4.png 634w" sizes="(max-width: 722px) 100vw, 722px" style="height: auto; max-width: 100%; vertical-align: middle; border: 0px;">
Method 3: init.d directory
The third method to run a program on your Raspberry Pi at startup is to add the program (to be run on boot) to the /etc/init.d directory. This directory contains the scripts which are started during the boot process (in addition, all programs here are executed when you shutdown or reboot the system).
Add the program to be run at startup to the init.d directory using the following lines:
sudo cp /home/pi/sample.py /etc/init.d/
Move to the init directory and open the sample script
cd /etc/init.d sudo nano sample.py
Add the following lines to the sample script to make it a Linux Standard Base (LSB) (A standard for software system structure, including the filesystem hierarchy used in the Linux operating system) init script.
# /etc/init.d/sample.py ### BEGIN INIT INFO # Provides: sample.py # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start daemon at boot time # Description: Enable service provided by daemon. ### END INIT INFO
init.d scripts require the above runtime dependencies to be documented so that it is possible to verify the current boot order, the order the boot using these dependencies, and run boot scripts in parallel to speed up the boot process.
You can learn to write init.d scripts following the guide here.
https://32414320wji53mwwch1u68ce-wpengine.netdna-ssl.com/wp-content/uploads/2014/11/test5.png 481w" sizes="(max-width: 604px) 100vw, 604px" style="height: auto; max-width: 100%; vertical-align: middle; border: 0px;">
Make the sample script in the init directory executable by changing its permission.
sudo chmod +x sample.py
Run this command:
sudo update-rc.d sample.py defaults
Now reboot to hear the Pi speak at startup.
Method 4: SYSTEMD
The fourth method to run a program on your Raspberry Pi at startup is to use the systemd files. systemd provides a standard process for controlling what programs run when a Linux system boots up. Note that systemd is available only from the Jessie versions of Raspbian OS.
Step 1– Create A Unit File
Open a sample unit file using the command as shown below:
sudo nano /lib/systemd/system/sample.service
Add in the following text :
[Unit] Description=My Sample Service After=multi-user.target [Service] Type=idle ExecStart=/usr/bin/python /home/pi/sample.py [Install] WantedBy=multi-user.target
You should save and exit the nano editor.
https://32414320wji53mwwch1u68ce-wpengine.netdna-ssl.com/wp-content/uploads/2014/11/test6.png 590w" sizes="(max-width: 635px) 100vw, 635px" style="height: auto; max-width: 100%; vertical-align: middle; border: 0px;">
This defines a new service called “Sample Service” and we are requesting that it is launched once the multi-user environment is available. The “ExecStart” parameter is used to specify the command we want to run. The “Type” is set to “idle” to ensure that the ExecStart command is run only when everything else has loaded. Note that the paths are absolute and define the complete location of Python as well as the location of our Python script.
In order to store the script’s text output in a log file you can change the ExecStart line to:
ExecStart=/usr/bin/python /home/pi/sample.py > /home/pi/sample.log 2>&1
The permission on the unit file needs to be set to 644 :
sudo chmod 644 /lib/systemd/system/sample.service
Step 2 – Configure systemd
Now the unit file has been defined we can tell systemd to start it during the boot sequence :
sudo systemctl daemon-reload sudo systemctl enable sample.service
Reboot the Pi and your custom service should run:
https://32414320wji53mwwch1u68ce-wpengine.netdna-ssl.com/wp-content/uploads/2014/11/test7.png 628w" sizes="(max-width: 733px) 100vw, 733px" style="height: auto; max-width: 100%; vertical-align: middle; border: 0px;">
Method 5: crontab
A detailed tutorial on using crontab to get a program running on boot can found here.
You can use any of these methods to run your program on boot as long as the point at which your Python script is run in the startup sequence is not vital. If your script relies on any system features being available at that point in time such as the network being connected and available, the /home/pi directory is mounted and ready for use or the System time has been updated by NTP then it would be ideal to use either systemd or init.d methods. These methods control the point in bootup at which your script is executed while booting.