close

Вход

Забыли?

вход по аккаунту

?

How to build your peripheral - RFberry Pi

код для вставки
RFberry Pi – How to build your peripheral.
An open source project powered by Esse Di Esse Elettronica
How to build your peripheral
-
Last Update 17/07/2014
1
RFberry Pi – How to build your peripheral.
Appendix
Introduction ....................................................................................................................................................... 3
1 – Concepts ...................................................................................................................................................... 3
1.1 – The network: master and peripherals .................................................................................................. 3
2 - The Hardware ............................................................................................................................................... 5
2.1 - Introduction to the microcontroller and radio transceiver ................................................................... 5
3 – Coding the Firmware ................................................................................................................................... 7
3.1 – How to send a command to the RF-SDS ............................................................................................... 7
3.2 - An Example of Serial Command ............................................................................................................ 7
3.3 - Steps to Initialise the RF-SDS ................................................................................................................. 8
2.4 – Get Network Parameter through default programming network ........................................................ 9
3.5 – Command received from RF-SDS ........................................................................................................ 11
3.6 – The indispensable Functions that the Peripheral has to implement.................................................. 12
3.7 – Pseudo Code of the Peripheral functions ........................................................................................... 13
4 - Creates Your Own Control Panel on the Website ...................................................................................... 13
2
RFberry Pi – How to build your peripheral.
Introduction
The RFberryPi Shield has a radio transceiver called RF-SDS, this radio module communicate through a serial
port.
Every peripheral has to have on board this transceiver RF-SDS and a microcontroller with a serial port,
otherwise it is not possible to send the data through the radio transceiver RF-SDS.
1 – Concepts
1.1 – The network: master and peripherals
Into the network the master is the RFberryPi and each peripheral has to be ready to receive/send data
from/to the RFberryPi.
Peripheral 1
Master:
Peripheral 2
RFberry Pi
Peripheral 3
The peripheral will send data to the RFberryPi when an input, output change or when the peripheral
receive an command from the RFberryPi.
PERIPHERAL DUTY:
A – Communicate the status change of any Input, Output or Special Functions to the RFberryPi.
Example:
1 - Input
Change
Peripheral 1
Master:
2 - Notify the
change of the
input status
RFberry Pi
B – RFberryPi send a command, if dictated by the architecture the peripheral reply.
Example:
3
RFberry Pi – How to build your peripheral.
1 - RFberryPi ask for the
status of an output
Peripheral 1
2 - Peripheral reply with the
output status
Master:
RFberry Pi
There is the possibility to communicate directly with another peripheral without communicate with the
master, but in this case the data showed by the RFberryPi on the GUI will be not synchronised with what is
happening into the network. If we will decide to make a smarter peripheral we should at least send a
notification to the RFberryPi.
For example in our network of peripherals we can decide to get an input from the “Peripheral 1” and set
the output on the “Peripheral 2”. Then we should notify the change of status of both peripherals to the
RFberryPi.
2 - Notify the change of
the input status
Master:
Peripheral 1
1 - Input
Change
3 – Send the command
to change the output
RFberry Pi
4 - Notify the output
status change
Peripheral 2
4
RFberry Pi – How to build your peripheral.
2 - The Hardware
2.1 - Introduction to the microcontroller and radio transceiver
Every peripheral need a smart component which can implement the architecture for communicate with the
RFberry Pi and the radio transceiver RF-SDS.
The smart component can be any microcontroller with a serial port with voltage levels that do not exceed
3.6V.
Microcontroller
RF-SDS
TX
RX
1
10
5
6
Figure 2.1.1: Serial connection between microcontroller and radio transceiver
The figure 2.1.1 shows a typical connection between microcontroller and RF-SDS. The radio transceiver has
the following pin functions:
PIN
1
2
3
4
FUNCTION
VCC 2.2V to 3.6V
GND
Sleep
RX
TYPE
Power Supply
Power Supply
Input (max 3.6V)
Input (max 3.6V)
5
6
7
8
CD
Busy
Active
TX
Output
Output
Output
Output
9
10
Reset
Reserved
Input (max 3.6V)
.
CONNECTION
MUST to be connected.
MUST to be connected.
MUST to be connected. If not used connect to GND.
MUST to be connected to the pin TX of the
microcontroller.
If not used do not connect.
If not used do not connect.
If not used do not connect.
MUST to be connected to the pin RX of the
microcontroller.
If not used do not connect.
Do not connect.
Thus, it is enough connect the power supply of 3.3VDC to the radio transceiver RF-SDS and connect the pin
TX of the RF-SDS to the pin RX of the microcontroller and then the pin RX of the RF-SDS to the pin TX of the
microcontroller.
5
RFberry Pi – How to build your peripheral.
If all connection has been made, it is ready to be programmed with the architecture and protocol, which it
is possible to find on this link:
http://support.rfberrypi.com/architecture
A suitable microcontroller can be a PIC, for example the PIC16F876 which is one often used by the
beginner.
Let see the pins functions of the PIC16F876:
The pins 18 and 17 are the pins where to connect RF-SDS.
6
RFberry Pi – How to build your peripheral.
3 – Coding the Firmware
3.1 – How to send a command to the RF-SDS
The RF-SDS has to be set with serial command, generally a command is a serial sequence of characters.
For example to send the command to set the fixed packet of bytes to send and receive for each wireless
transmission we have to send the serial commands:
C0416
Where “C04” is the command and the “16” is the number of bytes.
Now we have to convert this command in bytes to be ready to be sent with the serial port of our
microcontroller.
If we see an ASCII table each character has a hexadecimal value:
ASCII
character
HEX
value
�C’
�0’
�4’
�1’
�6’
0x43
0x30
0x34
0x31
0x36
Thus in output of the serial port we have to send the sequence:
0x43
0x30
0x34
0x31
0x36
Now the RF-SDS will send 16bytes for each wireless communication with another RF-SDS.
We are obligated to send 16bytes each time.
If we want send data from the RF-SDS on our peripheral to the RF-SDS connected to our Raspberry Pi
(RFberryPi) we have to always load 16bytes.
The command to load data and send data with the RF-SDS are explained in the next subchapter, we have to
remember we have to convert the command that we will see in ASCII characters into a hexadecimal bytes
to send through the serial port (as seen here).
3.2 - An Example of Serial Command
The radio transceiver accept a series of serial commands that have to be sent in ASCII format.
For example if we want send the status of a input to the RFberryPi we have to send the following ASCII
characters (upper case) to the RF-SDS:
Example:
ASCII string to send to RF-SDS: C30RBiabXXXXXXXXXXX
7
RFberry Pi – How to build your peripheral.
ASCII string to send to RF-SDS: C31
The first command C30 (command of the RF-SDS) is to load the data on the RF-SDS then the protocol of the
RFberryPi says we have to fill up with 16 bytes:
B0
B1
R
B
B2 B3
i
ID_input
B4
Value
B5
null
…… B15
null null
The first two bytes B0 and B1 are the ASCII characters �R’ and �B’ used as filter, then the RFberry Pi
command �I’ which indicate a status of an input, so follows the ID_input which is a number between 0 and
255 and the Value of the status which is again a number between 0 and 255, remain to fill up the bytes
between B5 and B15 where we can fill up with any ASCII character we want. The example fill up with �X’ .
We have to pay attention to the ID_input and Value, are numbers (byte) which has to be translated in ASCII
format. In the example there is ID_input=’a’ and Value=’b’ thus seeing an ASCII table we can see the
ID_input=97 (hex=61) and the Value=98 (hex=62), that means the peripheral has 99 or more inputs, in the
example only the 99th input status is sent to the RFberry Pi.
3.3 - Steps to Initialise the RF-SDS
Steps to initialise the RF-SDS:
1) Gives a 1 (3.3V) to the RESET (PIN9) and then give a 0
2) Gives the list of commands listed in the table 3.3.1
COMMAND
C0416
C072
C0001
C08
C151
C091
C100
C111
C200100
C210001
C220050
C2302
C291
DESCRIPTION
Set number of byte to send each transmission
Set TX power
Set the channel to use CH=1
Init the radio on the RF-SDS module
Set the RF-SDS to reply �*’ when a command sent has been executed correctly
Set auto AKN to on
Set frequency hopping off
Activating waiting for AKN
Set maximum waiting time to 10mS
Set maximum waiting time for AKN to 100mS
Set to 5mS the waiting time between two transmission when an error occur
Set to 2 the maximum number of retry
Set the module RF-SDS to answer OK when there is a successful transmission
Table 3.3.1: List of commands to initialise the RF-SDS
Follow the list of commands to send to the RF-SDS to initialise it. Remember all command are in ASCII
format and each character is upper case.
3) Now we have to initialise the network! But here we have to create an “IF”.
8
RFberry Pi – How to build your peripheral.
YES
NO
The network has been
already programmed?
Read the saved
network parameters
from the memory of
the microcontroller
Set default
parameters (as
wanted)
When the RFberry Pi is trying to link a new peripheral will goes on a default programming network, thus
the peripheral will get and memorize the network parameters for the current network.
To set the current network we have to send the following command to the RF-SDS:
COMMAND
C01xxxx
C02xxxx
C03xxxx
C0001
C08
DESCRIPTION
Set the network address. �x’ are 4 characters representing hexadecimal format.
Set the peripheral address. �x’ are 4 characters representing hexadecimal format.
Set the destination address (RFberryPi address). �x’ are 4 characters representing
hexadecimal format.
Set the channel to communicate with the RFberry Pi (in default network is 5 in
normal mode is 1)
Init the radio on the RF-SDS module
Table 3.3.2: List of commands to set the current network
Some commands has been repeated, we have already gave on the point 2 into the list of commands on the
table 3.3.1.
Table 3.3.2 is the routine to set the current network, as we will see in the next chapter, if the button has
been pressed we have to set the default programming network, then communicate with the RFberryPi (if
the function to find a new peripheral has been triggered on the RFberryPi) and then we use the list of
commands in table 3.3.2 to go back to the current network but with the �x’ substituted with the data
received from the RFberryPi.
2.4 – Get Network Parameter through default programming network
The peripheral has to have always a button. When the button is pressed has to be set the default
programming network:
COMMAND
C01FFFC
C02FFFC
C03FFFC
DESCRIPTION
Set the network address. �FFFC’ are 4 characters representing hexadecimal format.
Set the peripheral address. �FFFC’ are 4 characters representing hexadecimal format.
Set the destination address (RFberryPi address). �FFFC’ are 4 characters representing
hexadecimal format.
9
RFberry Pi – How to build your peripheral.
C0005
Set the channel to communicate with the RFberry Pi (in default network is 5 in
normal mode is 1)
Init the radio on the RF-SDS module
C08
Table 3.4.1: List of commands to set the default programming network
If on the RFberry Pi the function to find a new peripheral has been triggered then the peripheral will receive
data and has to reply.
If we see the chapter 4 on the “Introduction to the architecture and protocols”
(http://support.rfberrypi.com/architecture/) the RFberry Pi should begin to send the command �w’ and the
addresses of the current network.
The first 16bytes we have to parse into our peripheral will be:
B
0
B
1
B
2
B3
B4
B5
B6
B7
B8
B
9
…
….
B1
5
R
B
W
H_name_net
work
L_name_net
work
H_name_perip
heral
L_name_perip
heral
H_name_RFbe
rryPi
L_name_RFbe
rryPi
nu
ll
…….
null
Where:
-
R: is the ASCII character �R’ with hexadecimal value 0x52
-
B: is the ASCII character �B’ with hexadecimal value 0x42
-
w: is the ASCII character �w’ with hexadecimal value 0x77
-
H_name_network: is the MSbyte of the network address, it can have hexadecimal value
between 0x00 and 0xFF. This has to be used into the routine to set the current network. Thus
into the command “C01hhll” where hh are the ASCII characters of the hexadecimal value of the
byte H_name_network (1)
-
L_name_network: is the LSbyte of the network address, it can have hexadecimal value
between 0x00 and 0xFF. This has to be used into the routine to set the current network. Thus
into the command “C01hhll” where ll are the ASCII characters of the hexadecimal value of the
byte L_name_network (1)
-
H_name_peripheral: is the MSbyte of the peripheral address, it can have hexadecimal value
between 0x00 and 0xFF. This has to be used into the routine to set the current network. Thus
into the command “C02hhll” where hh are the ASCII characters of the hexadecimal value of the
byte H_name_peripheral (1)
-
L_name_peripheral: is the LSbyte of the peripheral address, it can have hexadecimal value
between 0x00 and 0xFF. This has to be used into the routine to set the current network. Thus
into the command “C02hhll” where ll are the ASCII characters of the hexadecimal value of the
byte L_name_peripheral (1)
-
H_name_RFberryPi: is the MSbyte of the RFberry Pi address, it can have hexadecimal value
between 0x00 and 0xFF. This has to be used into the routine to set the current network. Thus
into the command “C03hhll” where hh are the ASCII characters of the hexadecimal value of the
byte H_name_RFberryPi (1)
10
RFberry Pi – How to build your peripheral.
-
L_name_RFberryPi: is the MSbyte of the RFberry Pi address, it can have hexadecimal value
between 0x00 and 0xFF. This has to be used into the routine to set the current network. Thus
into the command “C03hhll” where ll are the ASCII characters of the hexadecimal value of the
byte L_name_RFberryPi (1)
(1) Note: the ASCII characters of the hexadecimal value is a conversion from hexadecimal to string.
If the hexadecimal value is 0xA2 then the two characters will be �A’ and �2’, thus to the RF-SDS has
to be sent 0x41 and 0x32.
Example:
For H_name_network = 0xA2 and H_name_network = 0x10
The command hexadecimal value to send to the RF-SDS of the command “C01hhll”
will be:
�C’
0x43
�0’
0x30
�0’
0x30
�h’
0x41
�h’
0x32
�l’
0x31
�l’
0x00
Now we have to set the current network sending the commands of the list table 2.3.2 but the �x’ has to be
substitute with the data received.
The RFberry Pi will then immediately try to communicate with the peripheral, thus have set the current
network the peripheral should be ready to parse any other command received from the RFberryPi on the
current network.
3.5 – Command received from RF-SDS
The RF-SDS will output on his serial port data only when the wireless transmission received contain the
network and peripheral addresses set with the commands “C01xxxx” and “C02xxxx”.
That means if there are more than 2 RF-SDS in a room and one transmit something, only one of the others
will gives in output a serial data (if the transmitter has transmitted wireless the right addresses).
Thus the microcontroller of the peripheral has not to take care to discard message which are not for him, it
will receive on its serial port only the data without any other information about addresses.
Because the architecture says for each transmission between two RF-SDS 16bytes of data has to be sent,
the microcontroller will see on its serial port coming group of 16bytes.
The list of the commands that has to be parsed by the microcontroller are into the chapter 4 on the
“Introduction to the architecture and protocols” (http://support.rfberrypi.com/architecture/) .
11
RFberry Pi – How to build your peripheral.
Example:
RFberry Pi sends the command to get back status of the input 3, on the serial port of the microcontroller is
received the hexadecimal value:
B0
B1
B2
B3
0x52 0x42 0x69 0x03
R
B
B4
0x2E
i
B5
0x2E
B6
0x2E
B9
……. B15
0x2E 0x2E 0x2E
.
ID_input
Thus the microcontroller has to read the status of the input and send back the status.
Let say the input 3 has value 1, then the microcontroller has to use the command “C30” to load the group
of 16 bytes and “C31” to make the RF-SDS to send wirelessly the data to the RFberry Pi.
Thus the sequence of byte to send with the serial port to the RF-SDS is:
B0
B1
B2
B3
B4
B5
B6
B7
B8
……. B18 B19 B20 B21
0x43 0x33 0x30 0x52 0x42 0x69 0x03 0x01 0x2E 0x2E 0x2E 0x43 0x33 0x31
C
3
0
R
B
i
.
C
3
1
ID_input
Value
The �.’ are used to fill up the remaining empty byte of the 16 bytes packet data (16 bytes packet data: B3 to
B18).
3.6 – The indispensable Functions that the Peripheral has to implement
If we have seen the chapter 4 on the “Introduction to the architecture and protocols”
(http://support.rfberrypi.com/architecture/) , then it obvious we have to implement a functions to reply to
the command that will be received from our microcontroller.
Here the list to indispensable functions to make our peripheral discoverable from the RFberry Pi:
-
Function to get the addresses of the network when command �w’ is sent using the default
programming network, we will call: w_GetRFberryPiNetwork()
Function to reply with the identification parameters of our peripheral, we will call:
t_PeriParameters()
Function to reply with the name of our peripheral, we will call: n_SendPeriName()
12
RFberry Pi – How to build your peripheral.
This above functions are indispensable because then the control panel on the GUI will be built using the
parameters given with this functions.
Then there are the other functions to do things with our peripheral:
-
Function to send the status of an input, we will call: i_SendInStatus()
Function to send the status of an output, we will call: p_SendOutStatus()
Function to get and set the parameters for a special function, we will call:
f_SetSpecialFunction()
Function to send the status and parameters of a special function, we will call:
u_SetSpecialFunction()
3.7 – Pseudo Code of the Peripheral functions
w_GetRFberryPiNetwork(): is a function which as to be triggered when the command �w’ is received from
the RFberryPi.
The pseudocode in C language:
4 - Creates Your Own Control Panel on the Website
13
Документ
Категория
Без категории
Просмотров
13
Размер файла
871 Кб
Теги
1/--страниц
Пожаловаться на содержимое документа