element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Clustered MCUs
  • Challenges & Projects
  • Project14
  • Clustered MCUs
  • More
  • Cancel
Clustered MCUs
Blog tinyMonster AIO Robot - RF remote
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Clustered MCUs to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: mahmood.hassan
  • Date Created: 24 Oct 2018 9:05 PM Date Created
  • Views 764 views
  • Likes 3 likes
  • Comments 1 comment
  • clusteredmcuch
  • irda
  • arduino project
  • arm mbed
  • arduino ide
  • esp-8266
  • stm32 nucleo
  • l298hn
  • nrf24l01
  • 16x2 lcd
Related
Recommended

tinyMonster AIO Robot - RF remote

mahmood.hassan
mahmood.hassan
24 Oct 2018

Previous Posts:

tinyMonster AIO Robot (part-1)

tinyMonster AIO Robot (part-2)

tinyMonster AIO Robot (part-3)

tinyMonster AIO Robot (part-4)

tinyMonster AIO Robot (part-5)

 

In this part I am going to explain how to built RF remote to control robot (or anything) using STM32F103C8T6 (aka blue pill), NRF24L01+, 2-axis analog joystick and few buttons (optional).

 

Hardware Used

 

{gallery} tinyMonster Robot - RF remote

image

IMAGE TITLE: STM32F103C8T6

image

MAGE TITLE: NRF24L01+ module

image

IMAGE TITLE: 2-Axis Analog Joystick

image

IMAGE TITLE: Buttons and Power Switch

image

IMAGE TITLE: Small LED with 470R resistors to indicate communication and switches position

image

IMAGE TITLE: Li-Ion single cell to 5V booster

image

IMAGE TITLE: Li-Ion 18650 single cell with its holder

image

IMAGE TITLE: Li-Ion single cell charger with protection circuit

 

Circuit Diagram

image

 

STM32F103C8T6 using Mbed

Before start programming we need to add STM32F103RB platform in mbed online compiler. In order to do that we will follow these step:

Goto:     https://os.mbed.com/platforms/ST-Nucleo-F103RB/

Click on "ADD to your Mbed Compiler" And it will take you to online compiler and add it to your platform list

image

 

After Adding NUCLEO-F103RB platform to Mbed online compiler. You can simply copy paste the code given below and add the STM32F103C8T6, NRF24L01+ and USB serial libraries from the important links.

 

#include "stm32f103c8t6.h"
#include "mbed.h"
#include "math.h" 
#include "USBSerial.h"
#include "nRF24L01P.h"

// The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's
//  "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019)
//  only handles 4 byte transfers in the ATMega code.
#define TRANSFER_SIZE   2


#define LED1 PB_3
#define LED2 PB_4
#define LED3 PB_5
#define LED4 PB_6

#define BUTTON1 PB_7
#define BUTTON2 PB_8
#define BUTTON3 PB_9
#define BUTTON4 PB_10


#define CSN  PC_14
#define CE   PC_15
#define IRQ  PB_1

#define LED_ON 1
#define LED_OFF 0


DigitalOut  myled1(LED1);//funcrion 1
DigitalOut  myled2(LED2);//function 2
DigitalOut  myled3(LED2);//function 3
DigitalOut  myled4(LED4);//tx activity

AnalogIn   xin(A0);
AnalogIn   yin(A1);
AnalogIn   bat_volt(PB_0);

DigitalIn  mybutton1(BUTTON1, PullUp);//funcrion 1
DigitalIn  mybutton2(BUTTON2, PullUp);//funcrion 2
DigitalIn  mybutton3(BUTTON3, PullUp);//funcrion 3
DigitalIn  mybutton4(BUTTON4, PullUp);//joystick sw


nRF24L01P my_nrf24l01p(SPI_MOSI, SPI_MISO, SPI_SCK, CSN, CE, IRQ);    // mosi, miso, sck, csn, ce, irq

int main() {
    char txData[TRANSFER_SIZE];
    int txDataCnt = 0;
    int rxDataCnt = 0;
    confSysClock();     // Configuring system clock
    USBSerial usbSerial(0x1f00, 0x2012, 0x0001,  false);    // connection is not blocked when USB is not plugged in

    myled1 = LED_OFF;      // turn the LED off
    myled2 = LED_OFF;    
    myled3 = LED_OFF;    
    myled4 = LED_OFF;    

    usbSerial.printf("STM32+nRF24L01+ Test\r\n");
    

    my_nrf24l01p.powerUp();

    // Display the (default) setup of the nRF24L01+ chip
    usbSerial.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency() );
    usbSerial.printf( "nRF24L01+ Output power : %d dBm\r\n",  my_nrf24l01p.getRfOutputPower() );
    usbSerial.printf( "nRF24L01+ Data Rate    : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
    usbSerial.printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
    usbSerial.printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );

    my_nrf24l01p.setTransferSize( TRANSFER_SIZE );

    my_nrf24l01p.setReceiveMode();
    my_nrf24l01p.enable();
    
    bool rf_remote_ctrl = false;
    bool func_1 = false;
    bool func_2 = false;
    bool func_3 = false;

    while (1) {
        float x_val = xin.read();
        float y_val = yin.read();
        
        if (!mybutton4){
            while (!mybutton4);
            rf_remote_ctrl=!rf_remote_ctrl;
            myled4 = rf_remote_ctrl;
        }

        if (rf_remote_ctrl){
            if ( x_val < 0.4f || x_val > 0.55f) {
                txData[txDataCnt++] = 'X';
                txData[txDataCnt++] = (char)(rintf)(x_val*100);
                if ( txDataCnt >= sizeof( txData ) ) {
                    my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
                    txDataCnt = 0;
                }
                usbSerial.printf( "tinyMonster Robot RF remote - X-axis value : %1.4f\r\n", x_val);
                myled4 = !myled4;
            }
            if ( y_val < 0.4f || y_val > 0.55f) {
                txData[txDataCnt++] = 'y';
                txData[txDataCnt++] = (char)(rintf)(x_val*100);
                if ( txDataCnt >= sizeof( txData ) ) {
                    my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
                    txDataCnt = 0;
                }
                usbSerial.printf( "tinyMonster Robot RF remote - Y-axis value : %1.4f\r\n", y_val);
                myled4 = !myled4;
            }

            if (!mybutton1) {
                while (!mybutton1);
                func_1 = !func_1;
                txData[txDataCnt++] = '1';
                txData[txDataCnt++] = ((func_1) ? '1' : '0');
                if ( txDataCnt >= sizeof( txData ) ) {
                    my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
                    txDataCnt = 0;
                }
                usbSerial.printf( "tinyMonster Robot RF remote - Function 1 : %d\r\n", func_1);
                myled1 = func_1;
            }
            if (!mybutton2) {
                while (!mybutton2);
                func_2 = !func_2;
                txData[txDataCnt++] = '2';
                txData[txDataCnt++] = ((func_2) ? '1' : '0');
                if ( txDataCnt >= sizeof( txData ) ) {
                    my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
                    txDataCnt = 0;
                }
                usbSerial.printf( "tinyMonster Robot RF remote - Function 2 : %d\r\n", func_2);
                myled2 = func_2;
            }
            if (!mybutton3) {
                while (!mybutton3);
                func_3 = !func_3;
                txData[txDataCnt++] = '3';
                txData[txDataCnt++] = ((func_3) ? '1' : '0');
                if ( txDataCnt >= sizeof( txData ) ) {
                    my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
                    txDataCnt = 0;
                }
                usbSerial.printf( "tinyMonster Robot RF remote - Function 3 : %d\r\n", func_3);
                myled3 = func_3;
            }
        }
        
        wait (0.001f);
    }

}

 

This code use the micro USB port of Blue pill for debugging. And pin names that can be used in Mbed code are either shown in Blue boxes with white text or Green boxes with White text

tinyMonster Robot - RF Remote STM32F103 pinout compatible with Mbed

 

Important Links

https://os.mbed.com/users/hudakz/code/STM32F103C8T6_Hello/

https://os.mbed.com/users/hudakz/code/mbed-STM32F103C8T6/

https://os.mbed.com/users/Owen/code/nRF24L01P/

https://os.mbed.com/users/cfb95/code/STM32F103C8T6_nRF24L01P_Hello_World/

https://os.mbed.com/users/hudakz/code/USBDevice_STM32F103/

  • Sign in to reply
Parents
  • genebren
    genebren over 6 years ago

    Nice addition to your project documentation.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • genebren
    genebren over 6 years ago

    Nice addition to your project documentation.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube