This Arduino compatible library allows for simple interfacing to wireless transmitter/receiver modules.
Currently supported Arduino boards:
All ATMega328 baed Arduino development board - Uno, Nano, Pro Mini etc
Currently supported products.
433MHz wireless transmitter MX-FS-03V & receiver modules MX-05 available via our store
https://hobbycomponents.com/wired-wirel ... -03v-mx-05
This library is provided free to support the open source community. We spend most of our time creating free content like this because we genuinely want to support the open source community. PLEASE SUPPORT US so that we can continue to create free content by purchasing products from our store - HOBBYCOMPONENTS.COM
You will need to download (please log in to download the library) and unzip this library to the Arduino development environments library area.
On Windows:
My Documents\Arduino\libraries\
On Mac:
Documents/Arduino/libraries/
Linux:
Usually found within the users home area under /Arduino/libraries/
Using the HCWireless library
To use the library just include the HCWireless.h header file and then create an instance of the library. E.g:
- #include "HCWireless.h"
- HCWireless HCWireless;
Before using the library it must first be initialised. To initialise the Tx part of the library (for transmitting data) place the following line in the Setup() loop at the top of the sketch:
- HCWireless.txInit(txPin);
Where:
txPin is the digital pin used to connect to the Tx input of the transmitter module.
To initialise the Rx part of the library (for receiving data) place the following line in the Setup() loop at the top of the sketch:
- HCWireless.rxInit(rxPin, rxBufferSize);
Where:
rxPin is the digital pin used to connect to the Tx output of the receiver module.
rxBufferSize is the size of the rx buffer in bytes. This must be equal or greater than the amount of data expected to be received in one transmission otherwise a buffer overrun error will be generated and the received data will rejected.
Returns:
A boolean true or false where true = memory allocation for Rx buffer was successful
false = not enough memory for Rx buffer
HCWireless library functions:
- byte HCWireless.send(payload);
payload is the variable, array, or structure to transmit.
Returns: void
Notes: Size of variable, array, or structure in bytes must not exceed the libraries
maximum Rx buffer size set by the HCWireless.rxInit() library function.
If data is currently being received this function will wait until reception
has completed before transmitting the data.
Whilst transmitting global interrupts are disabled.
- byte HCWireless.sendBytes(payload, payloadsize);
payload is the variable, array, or structure to transmit.
payloadsize in the size of the array or structure in bytes.
Returns: void
Notes: Size of variable, array, or structure in bytes must not exceed the libraries
maximum Rx buffer size set by the HCWireless.rxInit() library function.
If data is currently being received this function will wait until reception
has completed before transmitting the data.
Whilst transmitting global interrupts are disabled.
- byte HCWireless.available();
Returns: The amount of received data in bytes in the Rx buffer.
- byte HCWireless.read(payload);
payload is the variable, array, or structure to transfer the data in the Rx buffer into.
Returns: The status as a boolean value where TRUE = transfer successful, FALSE = transfer failed.
Notes: If there are insufficient bytes available in the Rx buffer the function will abort the
transfer and the Rx buffer will be cleared.
- byte HCWireless.readBytes(payload, payloadsize);
payload is the variable, array, or structure to transfer the data in the Rx buffer into.
payloadsize is the amount of data in bytes to transfer.
Returns: The status as a boolean value where TRUE = transfer successful, FALSE = transfer failed.
Notes: If there are insufficient bytes available in the Rx buffer the function will abort the
transfer and the Rx buffer will be cleared.
- byte HCWireless.state();
Returns: The error status as a byte value where 0 = no error.
A value other than zero means an error occurred.
To get the type of error you can logically and the returned value
with one of the following bit masks:
RX_BIT_ERROR // Bit error
RX_EOB_ERROR // End of byte error
RX_EOT_ERROR // End of transmission error
RX_OVR_ERROR // Buffer overflow error
RX_CRC_ERROR // CRC error
- [size=150][b]Example Tx Sketch:[/b][/size]
- /* FILE: HCWireless_Blink_Tx_Example.ino
- DATE: 19/06/19
- VERSION: 1.0
- AUTHOR: Andrew Davies
- 19/06/19 version 1.0: Original version
- This sketch demonstrates how to use the HCWireless library to remotely control the
- state of an LED connected to the Arduino at the receiving end. This sketch should be used
- in conjunction with the HCWireless_Blink_Rx_Example at the receiving end.
- Currently this sketch supports the following products:
- 433MHz wireless transmitter MX-FS-03V & receiver modules MX-05 available via our store
- https://hobbycomponents.com/wired-wireless/168-433mhz-wireless-modules-mx-fs-03v-mx-05
- This library is provided free to support the open source community.
- We spend most of our time creating free content like this because we genuinely
- want to support the open source community. PLEASE SUPPORT US so that we can
- continue to create free content by purchasing products from our store -
- HOBBYCOMPONENTS.COM
- You may copy, alter and reuse this code in any way you like, but please leave
- reference to HobbyComponents.com in your comments if you redistribute this code.
- This software may not be used directly for the purpose of selling products that
- directly compete with Hobby Components Ltd's own range of products.
- THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
- EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
- HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
- INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
- REASON WHATSOEVER.
- */
- #include "HCWireless.h"
- // Digital pin used to connect to the Tx modules data input pin
- #define TX_PIN 8
- // Create an instance of the library
- HCWireless HCWireless;
- boolean ledState = false;
- void setup()
- {
- // Initialise the Tx part of the library
- HCWireless.txInit(TX_PIN);
- }
- void loop()
- {
- // Send the current state of the LED
- HCWireless.send(ledState);
- // Toggle to LED state and wait 1 second before sending the new state
- ledState = !ledState;
- delay(1000);
- }
Example Rx Sketch:
- /* FILE: HCWireless_Blink_Rx_Example.ino
- DATE: 19/06/19
- VERSION: 1.0
- AUTHOR: Andrew Davies
- 19/06/19 version 1.0: Original version
- This sketch demonstrates how to use the HCWireless library to remotely control the
- state of an LED connected to the Arduino at the receiving end. This sketch should be used
- in conjunction with the HCWireless_Blink_Tx_Example at the transmitting end.
- Currently this sketch supports the following products:
- 433MHz wireless transmitter MX-FS-03V & receiver modules MX-05 available via our store
- https://hobbycomponents.com/wired-wireless/168-433mhz-wireless-modules-mx-fs-03v-mx-05
- This library is provided free to support the open source community.
- We spend most of our time creating free content like this because we genuinely
- want to support the open source community. PLEASE SUPPORT US so that we can
- continue to create free content by purchasing products from our store -
- HOBBYCOMPONENTS.COM
- You may copy, alter and reuse this code in any way you like, but please leave
- reference to HobbyComponents.com in your comments if you redistribute this code.
- This software may not be used directly for the purpose of selling products that
- directly compete with Hobby Components Ltd's own range of products.
- THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
- EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
- HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
- INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
- REASON WHATSOEVER.
- */
- #include "HCWireless.h"
- // Digital pin connected to the Rx modules data output pin
- #define RX_PIN 8
- // Digital pin connected to the LED
- #define LED_PIN 13
- // Set the size of the Rx buffer in bytes (max = 255 bytes)
- #define RX_BUFFER_SIZE 20
- // Create an instance of the library
- HCWireless HCWireless;
- void setup()
- {
- Serial.begin(9600);
- // Initialise the Rx part of the library
- boolean result = HCWireless.rxInit(RX_PIN, RX_BUFFER_SIZE);
- if(!result)
- {
- Serial.println("Error: Can't allocate memory for Rx buffer");
- while(1);
- }
- pinMode(LED_PIN, OUTPUT);
- }
- void loop()
- {
- // Check to see if an LED state has been received...
- if(HCWireless.available())
- {
- // ...if so then get the state and write it to the LED pin
- boolean state = HCWireless.readByte();
- digitalWrite(LED_PIN, state);
- }
- }
Disclaimer: Libraries, example code, and diagrams within this forum thread are provided as an additional free service by Hobby Components and are not sold as part of any product. We do not provide any guarantees or warranties as to their accuracy or fitness for purpose.
Descriptions and diagrams on this page are copyright Hobby Components Ltd and may not be reproduced without permission.