HowTo: FHEM – install nanoCul

A smart home system is only really fun when it can communicate with other components.
Since many systems use radio links for communication, it is only logical to make FHEM radio-enabled as soon as possible.

Most sensors and actuators in the smart home area use W-Lan and Bluetooth as well as frequencies in the 433 or 866 MHz range.
The last two are also gladly used by various radio weather stations, shutter controls, engine controls, etc ..

To make FHEM radio-enabled, there are two ways:
1. You buy yourself a finished USB to wireless adapter which is indeed ready but also expensive.
2. You build yourself a USB-to-wireless adapter and save a lot of money.

Do it yourself is not a problem in this case, because there is again a magnificent open-source project:
The nanoCul.
The nanoCul is a USB-to-wireless adapter that can be soldered and programmed from simple standard components. How the assembly works I have described in this article.

Hints for our lovely english readers: Basically, many of the articles on Nerdiy.de are translations from the original german articles. Therefore, it may happen here and there that some illustrations are not available in english and that some translations are weird/strange/full of mistakes or generally totaly wrong. So if you find some obvious (or also not obvious) mistakes don't hesitate to leave us a hint about that in the comment section. 
Also please don't get confused, that instead of a "dot" often a "comma" is used as decimal separator. 🙂


Safety instructions

I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/en/sicherheitshinweise/

Affiliate links / advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and shop via this link, Nerdiy.de receives a commission from the online shop or provider concerned. The price doesn't change for you. If you do your purchases via these links, you will support Nerdiy.de in being able to offer further useful projects in the future. 🙂


Requirements

Helpful Articles:
Before you can start installing the nanoCuls, you should have prepared the RaspberryPi so that it can be reached via Putty and FHEM is installed on it.
The following three articles describe what to do to prepare the RaspberryPi:
RaspberryPi – Setting up for Nerdiys!
RaspberryPI – The First Configuration!
RaspberryPi – Control the RaspberryPi via SSH

Required material:
-none-

Required material:

In the following list you will find all the parts you need to implement this article.


Construction of the nanoCul

The nanoCul essentially consists of four important components:

1. The CC1101 radio module: This is available for both 433Mhz and 866Mhz
2. A level converter: Since the CC1101 radio module (3.3V) and the Arduino Nano (5V) work with different logic levels, they have to be adapted respectively.
3. An Arduino Nano: A microcontroller that is relatively easy to program and operate via the USB interface.
4. The board on which everything is soldered together.
5. Optional: A housing so that the whole thing is protected.


Connect nanoCul to the RaspberryPi

To connect the nanoCul to the RaspberryPi you have to connect the nanoCul to the RaspberryPi via a USB cable. This can be a micro or mini USB cable (depending on the equipment of the Arduino Nano used).
Insert the USB cable into the RaspberryPi. (Which USB port you use on the RaspberryPi does not matter.)
Plug USB cable into the nanoCul. As soon as your RaspberryPi is switched on, at least one LED should light up on the nanoCul. If this bothers you, you can either cover the LED on the nanoCul with tape, paint over with a well-covering pen or even solder it out.

Install AVR C-Cross Compiler

In order to adapt the firmware (some kind of the operating system of the nanoCul) to our needs, we have to compile it ourselves. For this we first have to install the AVR C-Cross Compiler.
After you have logged in via Putty on the RasPi this is done with the following command.

sudo apt-get install make gcc-avr avrdude avr-libc

During installation, you may be asked if you agree that the installation will consume additional space. You confirm this demand with a “j”(or “y”) and enter. The installation will then continue.


Download nanoCul firmware

To download now the current firmware for the nanoCul you must first raussuchen the current link. Go to: https://sourceforge.net/p/culfw/code/HEAD/tarball

There will be the first pop up a download window. You close it because you want to load the code onto the RaspberryPi and not onto your computer.
Now you copy the download link by clicking with the right mouse button on “direct link” and then on “copy link address”. The link is now in your clipboard and you can paste it into Putty. Before you click on Enter in Putty, you have to put a “wget” in front of it so that the RasPi also knows that he should download the file given in the link.

For example, the full command would look like this for the current version (556):

wget https://sourceforge.net/projects/culfw/

The RasPi then downloads the file and displays the progress in a small animation.


Unpack the firmware

The downloaded firmware is now hidden in a zip archive. To continue working with it we first have to unpack it.
This works (with the current version) with the command:

unzip culfw-code-566-trunk.zip

If the version (in the example the 566) have changed meanwhile you have to adjust the part behind the “unzip” according to your version.


Change to the folder with the firmware

Now you have to switch to the folder just created by unzipping.
The command is:

cd culfw-code-566-trunk/culfw/Devices/nanoCUL


Here again is the part with the “566” to see if the version may have changed.


Set board.h correctly

Before we compile the firmware, we need the parameters
set correctly. This happens in the file “board.h”. This is
in the folder you just switched to.
With the command

sudo nano board.h

you get into the text editor “nano” and can use it to edit the file “board.h”.
Do not be scared: The console view disappears and it all looks a little different.

Here you can set various parameters. For example, the clock frequency of the microcontroller or the radio frequency of the radio module.

If you want to use a radio module with 433Mhz and your microcontroller or the Arduino board corresponds to an Arduino you need not change anything here.

However, if you use a radio module with 866Mhz, you need to change the following part.
Use the arrow keys on your keyboard to navigate to the location “#define HAS_CC1100_433” and write “//” before that.
This comments out this part and tells the compiler that he has the
Firmware should assemble so that they are not for a 433Mhz but
for an 866Mhz wireless adapter.

To save your changes in the board.h file, press CTRL + X, then
“j” (because you want to save the changed file) and then on
Enter. Nano closes then and you are back in the console.


Assemble firmware

This step is easy. The command is:

make

This command causes the firmware you just configured to compile now. This means that the human-readable code is translated into the machine language and can then be programmed into the microcontroller of the nanoCul in the next step.


Program firmware

After the firmware has been compiled, it is now time to program them into the microcontroller of the nanoCul.
You will need to enter the following command:

make program

The microcontroller is programmed and the programmed code is then checked again.


Find out the ID of the nanoCul

To register nanoCul in FHEM, we first need to get his unique ID.
This is important because otherwise conflicts could occur if, for example, two nanoCuls are connected to a RaspberryPi. (for example because you want to run one for 433Mhz and one for 866Mhz).
In order to get the correct ID, there should be nothing connected to the RaspberryPi besides the nanoCul.
The ID of nanoCul is then read with the following command:

ls /dev/serial/by-id

An ID is then output. In my case, it is the “usb-1a86_USB2.0-serial-if00-port0”. Of course, this ID can be different for you. Now we have to remember this ID, because it is needed for the next step


Register nanoCul in FHEM

In order to register the nanoCul in FHEM you have to switch to the web interface of FHEM. There is an input field in the upper area where we can enter the definition of nanoCul.
This definition reads:

define nanoCUL CUL /dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0@38400 1234

“NanoCul” stands for the name of your nanoCul in FHEM. You can also choose a different name here.
“CUL” describes the function of the defined device and must not be changed.
“/Dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0”
stands for the interface to nanoCul. Here you have to go now
Make sure you use the ID found in the previous step.
“@38400”
stands for the baud rate (~ speed) with the FHEM with the nanoCul
communicated. This value must be 38400.
“1234” is a code that is actually only needed when the nanoCUL FHT diagrams
should send. Then this must be adjusted accordingly. Either way, this must be specified with.

If you have your definition of your ID “assembled” you just have to transfer them to the text field in FHEM and press Enter.
You will then be redirected to this overview of the newly created nanoCUL. Here you can adjust everything important concerning nanoCul.
But now to test whether the nanoCul was successfully detected, you set “get nanoCul …” to “get nanoCul version” and click on “get”.
You should then receive a message such as: “nanoCUL version => V 1.67 nanoCUL868”. If you do not receive an answer here, check the ID of your nanoCul again as described in step 9. Otherwise, it sometimes helps to disconnect the nanoCul again from the RaspberryPi and reconnect or reprogram the nanoCul again. A restart of the RasPi’s solves the problem often.

If everything works, remember to save your FHEM configuration by clicking on “Save Config” in the left bar.

You should now have a nanoCul connected to your RaspberryPi and registered in FHEM.


Have fun with the project

I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂

P.S. Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you appreciate it that I share these information with you, I would be happy about a small donation to the coffee box. 🙂

Buy Me a Coffee at ko-fi.com   

8 comments

  1. Hi,
    sorry – I am not able to download the correct file.
    I tried to create the board.h file on the raspberry by just copy the code from the website, but when I try to start the “make” process, the output is “nothing to be done for ‘board.h’.
    So can you please update your nice how-to by the new link to the updated file?
    Thank you very much!

    1. Hi Frank,
      could you please tell me which file you can not download? 🙂
      The culfw firmware seems to be downloadable.
      Best regards
      Fabian

          1. Hi Fabian,

            great, now it works 🙂

            Thank you very much for your support!
            Best Regards
            Frank

  2. Pingback: Fhem Cul Anmelden

Leave a Reply

Your email address will not be published.