Ive been using my FTDI basic to program arduino pro minis for years without any problems, until today when it bricked two in a row. The FTDI is 5V, the pro minis. How to use cheap Chinese Arduinos that come with with CH340G CH341G SerialUSB chip Windows Mac OSX a blog by Konstantin Gredeskoul about Arduino, hardware. Connecting and programming n. RF2. 4L0. 1 with Arduino and other boards. Connecting n. RF2. L0. 1 and Arduino. Now, when we know n. RF2. 4L0. 1 module pinout we can now connect it to Arduino or some other board. Just connect pins on the same name on Arduino board and n. RF2. 4L0. 1 wireless module Connecting n. RF2. 4L0. 1 and Arduino. Schematic is very universal and fits for all the Arduinos UNO, DUE, MEGA, Leonardo, Yun etc. Arduino 1. 0 R3 standard, but also with older boardsSPI signals are in the ICSP connector. For connecting we suggest using femalefemale jumper wires type FF. The rest of the signals can be connected using a femalemale jumper wires type FM. Connect power pins from n. RF to Arduino as shown below n. RF2. 4L0. 1 ARDUINOVCC3. VGNDGNDCE and CSN pins can be connected to any digital pins. Then in RF2. 4 library, you can specify which pins you used. I chose pins 7 and 8 because I will use them in the examples. On Arduino UNO boards SPI pins are connected with some digital pins. While using modem you most remember that these digital pins wont be available. MOSI is connected to the digital pin 1. MISO is connected to the digital pin 1. SCK is connected to the digital pin 1. SS not used, but also blocks is connected to the digital pin 1. The Arduino MEGA 1. MOSI is connected to the digital pin 5. MISO is connected to the digital pin 5. SCK is connected to the digital pin 5. SS is connected to the digital pin 5. On the Arduino DUE, Yun and Leonardo SPI pins are on ICSP connector, and are independent of the digital pins. Programming n. RF2. L0. 1Having module connected, we need to program it. First program you probably know, well make traditional Hello World. We will make one device with the modem, will send the string to the other device. The second device will send the received string to a stationary computer and them will display it in the Arduino Serial Port Monitor. In this project we used RF2. Github RF2. 4 library on Github. You only need to click on Download ZIP button and itll start downloading all necessary things. You can install the library in Arduino IDE using Sketch Import library Add library. Another way is to extract the zip file to your Arduino home directory Arduinolibraries on Linux or Documents Arduinolibraries in Windows. Transmitter program will look like include lt SPI. RF2. 4L0. 1. h. RF2. 4. h. RF2. Addr6 0. 00. Retries1. 5, 1. 5. Writing. Piperx. Addr. radio. stop. Listening. constchar text Hello World. At the beginning of the sketch we infrom the program that well use libraries. SPI. h to handle the communication interface with the modemn. RF2. 4L0. 1. h to handle this particular modem driver. RF2. 4. h the library which helps us to control the radio modem. Next, we need to create an object called radioRF2. This object represents a modem connected to the Arduino. Arguments 7 and 8 are a digital pin numbers to which signals CE and CSN are connected. If you have connected them to other pins can change this arguments. Then I create a global array called rx. Addr. const byte rx. Addr6 0. 00. In this array we wrote the address of the modem, that will receive data from Arduino. Address has value 0. The address is necessary if you have a few modems in the network, thanks to the address, you can choose a particular modem to which you are sending the data. In the setup function we call the method radio. It activates the modem. Next we call radio. Retires1. 5, 1. 5 function. It shows how many times the modem will retry to the send data in case of not receiving by another modem. The first argument sets how often modem will retry. It is a multiple of 2. So, if the recipient does not receive data, modem will try to send them every 3. Second argument is the number of attempts. So in our example, modem will try to send 1. The method of radio. Writing. Pipe rx. Addr sets the address of the receiver to which the program will send data. Its argument is an array previously made with the receiver address. The last method in the setup function is radio. Listening. It switch the modem to data transmission mode. In the loop function, we start with creating a string that we want to send using modem. Hello World Its an array of charactersletters to which we assigned a Hello World text. Then, using the method of radio. Writing. Pipe. First argument is an indication of the variable that stores the data to send. Thats why we used before the variable name, so we can make an indicator from this variable. The second argument is the number of bytes that the radio will take from a variable to be sent. Here we used the function sizeof, which automatically calculates the number of bytes in a text string. Through this method, you can send up to 3. Because that is the maximum size of a single packet data modem. If you need confirmation that the receiver received data, the method radio. If it returns true, the data reached the receiver. If it returns false this data has not been received. The radio. write method blocks the program until it receives the acknowledgment or until you run out of all attempts to transmit established methods set in radio. Retires. The last part of the loop function is delay 1. It blocks the program for 1. It makes the program will sent Hello World every second to the receiver. The receiver. The program of the receiver in the second modem device will look like this include lt SPI. RF2. 4L0. 1. h. RF2. 4. h. RF2. Addr6 0. 00. Serial. Serial. begin9. Reading. Pipe0, rx. Addr. radio. start. Listening. if radio. Serial. printlntext. The program looks quite similar to the program of the transmitter. First we selected libraries which will be used and then we creates a radio object with selected control pins. In the next line you can see a table with the address of the receiver the same as in the transmitter. At the beginning of the setup function we set the object Serial for communication Arduino with the computer. Serial This part is waiting for the Arduino USB port switches to serial COM port when You connect USB cable. That is true for Arduino with ATmega. Leonardo, for ATmega. USBSerial communication Serial is available always. The method of Serial. USB COM. The next part of the function is to set the n. RF2. 4L0. 1 modem. Like before we used radio. The next line of the program is radio. Readin. Pipe 0, rx. Addr, which determines the address of our modem which receives data. The first argument is the number of the stream. You can create up to 6 streams that responds to different addresses. We created only address for the stream number 0. The second argument is the address to which the stream will react to collect the data. In this example we set the address assigned to a rx. Addr array. The next step is to enable receiving data via modem using the method radio. Listening. From that moment the modem waits for data sent to the specified address. In the loop function, program performs the following operations. First checks whether any data have arrived at the address of the modem using the method radio. This method returns a true value if we received some data, or false if no data. If the data was received, then it creates a 3. To read the data we use the method radio. The first argument is an indicator of the variable to which you want to save the data received by the modem. To present a variable as an indicator we applied the character in front of its name. The second argument is the amount of data to be stored in a variable. Here, we again have used the sizeof function, which automatically calculates the size of the text array. When data is received, it sends it to the Serial. Then the received text is being sent to a computer, where you can see it in the Serial Port Monitor using the Arduino IDE. If you did everything ok and there are no mistakes in connections, you should see the same values in your Serial Port Monitor Serial Port Monitor showing communication. Stay tuned for next articles. We have connected n. RF2. 4L0. 1 with Arduino, we will cover Teensy 3.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
September 2018
Categories |