element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Blog PSoC 6 and ModusToolbox: FreeRTOS to AWS MQTT
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 28 Mar 2021 7:10 PM Date Created
  • Views 7982 views
  • Likes 2 likes
  • Comments 33 comments
  • mqtt
  • aws
  • psoc_6
  • freertos
  • aws_iot
  • cypress
Related
Recommended

PSoC 6 and ModusToolbox: FreeRTOS to AWS MQTT

Jan Cumps
Jan Cumps
28 Mar 2021

In this post we react on a message on the RTOS queue and publish its payload on Amazon's AWS IoT MQTT service.

image

 

Together with the two previous posts, this one describes a hardware component in the NanoDrone II project of balearicdynamics

Scenario: receive 16 bytes of payload from an Arduino over serial, and forward it to AWS cloud.

The summary of the flow:

  • 2 main tasks, one for the UART with Arduino, one for MQTT with AWS.
  • all tasks sleep.
  • when Arduino sends 16 bytes, a trigger fires, and it wakes up the UART task.
  • UART task copies payload from UART buffer, and puts it on a RTOS queue as a message.
  • UART task back to sleep.
  • When a message is on the queue, the MQTT task wakes up
  • gets the message data from the queue and publishes a new message on AWS MQTT service with that data as payload.
  • MQTT task back to sleep
  • repeat

The two tasks run and sleep independently. The queue has 10 positions and can act as a UART data buffer if there's a slowness in publishing the message on AWS cloud.

 

Instead of showing the whole exercise, I'm going to point you to the AnyCloud MQTT Client example that this firmware borrowed from.

What have we changed:

  • the MQTT topic. It was "ledstatus". we use "nanodrone"
  • the trigger: a button press in the PSoC example. We use a message on the queue as trigger
  • subscribe: the original example subscribes to the same message as posted, then toggles the user led. We don't subscribe. One way traffic.
  • We introduced a queue to interact between the UART and MQTT client.
  • Changed power modes in the RTOS config. To keep the UART reactive.

 

The firmware is available on github: https://github.com/alicemirror/Nanodrone-II_PSoC6 .

Before cloning the project, check out the original AnyCloud MQTT Client example in ModusToolbox.

It serves two purposes: you have an example, and it takes care that the dependencies are all available in your workspace.

Follow its instructions to connect you to AWS MQTT. You'll need to do the exact same steps with our project. If you know it works with the standard example, it makes the next steps easier.

 

After cloning and importing the project into your workspace, perform these activities in the Quick Panel:

  • open the Library Manager and click Update. Close when finished.
  • click Refresh Quick Panel.
  • update mqtt_client.h with your Amazon certificates, and wifi_config.h with your WiFI settings, as you'd do for the AnyCloud MQTT Client example.
  • click Build Nanodrone-II_PSoC Application

 

Then connect  a 3.3 V Arduino. GND to PSoC 6 GND, TX with PSoC 6 pin 10.0.

Program this example on the Arduino: a simple program that will send 16 bytes once every time the Arduino resets.

 

void setup() {
  // start serial port at 9600 bps and wait for port to open:
  Serial1.begin(9600);
  establishContact();
}


void loop() {
    delay(100000);
}

void establishContact() {
    Serial1.print("{\"a\":-122,\"b\":3}");   // send a fixed lenght string
}

 

If all is well, you should get a message on your MQTT Cloud account each time you press the Arduino reset button.

 

image

 

PSoC 6 series
PSoC 6 and ModusToolbox: Create a Project with its own Board- and Module configurations
PSoC 6: Low Power Management - Power consumption without WiFi or Bluetooth
PSoC 6 and ModusToolbox: Create a FreeRTOS 10.3 Project
PSoC 6 and ModusToolbox: UART receiver with FreeRTOS
PSoC 6 and ModusToolbox: FreeRTOS message queue
PSoC 6 and ModusToolbox: FreeRTOS to AWS MQTT
PSoC 6 and ModusToolbox: Break the Debugger from the Proto Board
  • Sign in to reply
  • Jan Cumps
    Jan Cumps over 3 years ago in reply to skruglewicz

    You need to send exactly 26 bytes.

    This is balearicdynamics's test program: https://github.com/alicemirror/Nanodrone-II-Arduino/blob/main/TestSerial/TestSerial.ino

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • skruglewicz
    skruglewicz over 3 years ago in reply to Jan Cumps

    The pins on the Arduino Nano 33 IoT are:

     

    image

    CODE:

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • skruglewicz
    skruglewicz over 3 years ago in reply to Jan Cumps

    HI Jan Cumps

     

    Thanks so much for your help. I was able to find the correct pin to use, using the device configurator.

    SCB 5 was being used by the debugger.

    I then decided to use P0_2 on header J10 pin I00

    I set the ,h file with the the proper defines.

     

    To test, I set a breakpoint as you described

    The breakpoint is never reached. At this point I don't know why?

    It might be a problem now on the Arduino side with the way the Serial function is being called.

    If you see anything unusual with this let me know.

    I'll continue to experiment with the Arduino code.

     

    image

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 3 years ago in reply to skruglewicz

    Check UART

     

    Let's first check if you are getting Nano data into the PSoC 6 UART.

     

    The pin you selected isn't connected to the PSoC6:

    image

     

    ORANGE pins connect directly to the radio subsystem. They aren't connected to PSoC6 IC.

    You have to select one of the available BLACK pins, in combination with the explanation below.

     

    there is no pin 10.0 on my kit?

    I think there is. On Arduino A0 (see capture from user guide above). You could use that and move your analog heartbeat input to A3?

    If you want to test with that 10.0, proceed to the Test UART section below. Else continue reading:

     

     

    On the PSoC 6, you have to determine which of the available UARTs you 'll use.

    For that UART you then have to select one of the valid receive pin options.

    In my project, I created the file you are mentioning, configs/uart_config.h,.

     

    It uses serial block 1 for the UART, with p10_0 as RX.

    There is also a commented out example for serial block 5, as inspiration in case you'd like to use another serial block.

     

    // SCB 1 p10_0 rx p10_1 tx
    
    #define UART_SCB SCB1
    #define UART_PORT       P10_0_PORT
    #define UART_RX_NUM     P10_0_NUM
    #define UART_TX_NUM     P10_1_NUM
    #define UART_RX_PIN     P10_0_SCB1_UART_RX
    #define UART_TX_PIN     P10_1_SCB1_UART_TX
    #define UART_DIVIDER_NUMBER 1U
    
    #define UART_CLOCK PCLK_SCB1_CLOCK
    
    #define UART_INTR_NUM        ((IRQn_Type) scb_1_interrupt_IRQn)
    
    
    // SCB 5 p5_0 rx p5_1 tx
    
    //#define UART_SCB SCB5
    //#define UART_PORT       P5_0_PORT
    //#define UART_RX_NUM     P5_0_NUM
    //#define UART_TX_NUM     P5_1_NUM
    //#define UART_RX_PIN     P5_0_SCB5_UART_RX
    //#define UART_TX_PIN     P5_1_SCB5_UART_TX
    //#define UART_DIVIDER_NUMBER 5U
    //
    //#define UART_CLOCK PCLK_SCB5_CLOCK
    //
    //#define UART_INTR_NUM        ((IRQn_Type) scb_5_interrupt_IRQn)

     

    You can try to find an available RX pin by opening the Device Configurator  (we'll make changes here but abandon them - this is just for investigation), select one of the serial blocks (SBC), set is as ART, then check what pins are available (see below).

    Once you find a good combination for your board, write down the SBC#, the pins you chose (write down bot RX and TX pins, although TX will not be used by the program).

    Then close the configurator WITHOUT SAVING. We only use it to find available combinations.

    image

     

    Adapt the uart_config.h so that your settings are assigned. Use the current SBC1 and SBC5 examples as guideline of what to change.

     

    if you prefer to look into a source file for valid combinations of UARTs on your PSoC, you can open:

    /mtb_shared/mtb-hal-cat1/release-v1.6.0/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_02_124_bga.c

    Then search for the word scb_uart_rx

     

    You'll find two sections with available RX and TX pins:

     

    /* Connections for: scb_uart_rx */
    const cyhal_resource_pin_mapping_t cyhal_pin_map_scb_uart_rx[19] = {
        {&CYHAL_SCB_0, P0_2, (uint8_t)CY_GPIO_DM_HIGHZ, P0_2_SCB0_UART_RX},
        {&CYHAL_SCB_7, P1_0, (uint8_t)CY_GPIO_DM_HIGHZ, P1_0_SCB7_UART_RX},
        {&CYHAL_SCB_1, P2_0, (uint8_t)CY_GPIO_DM_HIGHZ, P2_0_SCB1_UART_RX},
        {&CYHAL_SCB_9, P2_4, (uint8_t)CY_GPIO_DM_HIGHZ, P2_4_SCB9_UART_RX},
        {&CYHAL_SCB_2, P3_0, (uint8_t)CY_GPIO_DM_HIGHZ, P3_0_SCB2_UART_RX},
        {&CYHAL_SCB_7, P4_0, (uint8_t)CY_GPIO_DM_HIGHZ, P4_0_SCB7_UART_RX},
        {&CYHAL_SCB_5, P5_0, (uint8_t)CY_GPIO_DM_HIGHZ, P5_0_SCB5_UART_RX},
        {&CYHAL_SCB_10, P5_4, (uint8_t)CY_GPIO_DM_HIGHZ, P5_4_SCB10_UART_RX},
        {&CYHAL_SCB_3, P6_0, (uint8_t)CY_GPIO_DM_HIGHZ, P6_0_SCB3_UART_RX},
        {&CYHAL_SCB_6, P6_4, (uint8_t)CY_GPIO_DM_HIGHZ, P6_4_SCB6_UART_RX},
        {&CYHAL_SCB_4, P7_0, (uint8_t)CY_GPIO_DM_HIGHZ, P7_0_SCB4_UART_RX},
        {&CYHAL_SCB_4, P8_0, (uint8_t)CY_GPIO_DM_HIGHZ, P8_0_SCB4_UART_RX},
        {&CYHAL_SCB_11, P8_4, (uint8_t)CY_GPIO_DM_HIGHZ, P8_4_SCB11_UART_RX},
        {&CYHAL_SCB_2, P9_0, (uint8_t)CY_GPIO_DM_HIGHZ, P9_0_SCB2_UART_RX},
        {&CYHAL_SCB_1, P10_0, (uint8_t)CY_GPIO_DM_HIGHZ, P10_0_SCB1_UART_RX},
        {&CYHAL_SCB_5, P11_0, (uint8_t)CY_GPIO_DM_HIGHZ, P11_0_SCB5_UART_RX},
        {&CYHAL_SCB_6, P12_0, (uint8_t)CY_GPIO_DM_HIGHZ, P12_0_SCB6_UART_RX},
        {&CYHAL_SCB_6, P13_0, (uint8_t)CY_GPIO_DM_HIGHZ, P13_0_SCB6_UART_RX},
        {&CYHAL_SCB_12, P13_4, (uint8_t)CY_GPIO_DM_HIGHZ, P13_4_SCB12_UART_RX},
    };
    
    /* Connections for: scb_uart_tx */
    const cyhal_resource_pin_mapping_t cyhal_pin_map_scb_uart_tx[19] = {
        {&CYHAL_SCB_0, P0_3, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P0_3_SCB0_UART_TX},
        {&CYHAL_SCB_7, P1_1, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P1_1_SCB7_UART_TX},
        {&CYHAL_SCB_1, P2_1, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P2_1_SCB1_UART_TX},
        {&CYHAL_SCB_9, P2_5, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P2_5_SCB9_UART_TX},
        {&CYHAL_SCB_2, P3_1, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P3_1_SCB2_UART_TX},
        {&CYHAL_SCB_7, P4_1, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P4_1_SCB7_UART_TX},
        {&CYHAL_SCB_5, P5_1, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P5_1_SCB5_UART_TX},
        {&CYHAL_SCB_10, P5_5, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P5_5_SCB10_UART_TX},
        {&CYHAL_SCB_3, P6_1, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P6_1_SCB3_UART_TX},
        {&CYHAL_SCB_6, P6_5, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P6_5_SCB6_UART_TX},
        {&CYHAL_SCB_4, P7_1, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P7_1_SCB4_UART_TX},
        {&CYHAL_SCB_4, P8_1, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P8_1_SCB4_UART_TX},
        {&CYHAL_SCB_11, P8_5, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P8_5_SCB11_UART_TX},
        {&CYHAL_SCB_2, P9_1, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P9_1_SCB2_UART_TX},
        {&CYHAL_SCB_1, P10_1, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P10_1_SCB1_UART_TX},
        {&CYHAL_SCB_5, P11_1, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P11_1_SCB5_UART_TX},
        {&CYHAL_SCB_6, P12_1, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P12_1_SCB6_UART_TX},
        {&CYHAL_SCB_6, P13_1, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P13_1_SCB6_UART_TX},
        {&CYHAL_SCB_12, P13_5, (uint8_t)CY_GPIO_DM_STRONG_IN_OFF, P13_5_SCB12_UART_TX},
    };

     

    Select a combination where the RX pin is available on your proto board's connectors. There are 19 combinations to chose from.

    A possible combination is the first one available:

    image

    P0_2_SCB0_UART_RX

    P0_3_SCB0_UART_TX

     

    Your uart_config.h file would look like this (untested!):

     

    // SCB 0 p0_2 rx p0_3 tx
    
    #define UART_SCB SCB0
    #define UART_PORT       P0_0_PORT
    #define UART_RX_NUM     P0_2_NUM
    #define UART_TX_NUM     P0_3_NUM
    #define UART_RX_PIN     P0_2_SCB0_UART_RX
    #define UART_TX_PIN     P0_3_SCB0_UART_TX
    #define UART_DIVIDER_NUMBER 0U
    
    #define UART_CLOCK PCLK_SCB0_CLOCK
    #define UART_INTR_NUM        ((IRQn_Type) scb_0_interrupt_IRQn)

     

    And you'd connect your Nano TX pin to the P0_2 of your board.

     

    Test UART:

     

    Set a breakpoint in uart_task.c, on the first line of the interrupt handler UART_Isr().

    image

     

     

    Connect the TX with your chosen RX pin, and connect the grounds of both devices.

    Send exactly 26 characters with 9600 baud / 8 bits / 1 stop / No parity from the nano.

    If the code does not break at this point, there's something wrong with the UART config explained above.

     

    If this works, please confirm and we can continue to analyse the downstream towards AWS.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • skruglewicz
    skruglewicz over 3 years ago

    Hi Jan Cumps

    I hope this comment finds you well.

    I 'm having some trouble connecting an Arduino Nano 33 IoT to my PSoC6 CY8CKIT and getting this project to work. I'm not getting any error, but the AWS output you described. Nothing is showing up on the nanodrone tAWS hing.

    You did help me with Building the new version of the project stated in the above thread and I was hoping you could give me some insight into why it doesn't appear to be working with my 2 boards.

    The Arduino was used for a Design Challenge "Design for a cause 2021" and the PSoC6 is being used for an existing challenge "Low Power IoT design challenge".

    I realize I'm using 2 different boards than you are for this project and I'm wondering if I have the connections and software correct for these 2 boards?

    I've Followed your steps above, in summary:

    • I experimented with and was able to get the Anycloud MQTT client example to run by:
      • Creating a ''Thing" on AWS called "ledstatus"
      • It connected ok and I was able to subscribe to ledstatus and see the button press events as described.
    • When using your project:
      • I created another Thing called nanodrone
      • I used the keys generated when creating the thing,  in the "mqtt_client_config.h" file
      • I was able to build the project
      • On the the Arduino I created a sketch as you described above.
      • I then connected 2 jumper wires between the 2 kits as you described above.
        • there is no pin 10.0 on my kit?
        • so I used the RX pin
        • Described on the wiring diagram in the Low Power IoT challenge blog.
      • The code runs and displays status messages on the terminal that the WiFi is connected and the AWS MQTT broker is connected.
      • When I press the reset button on the Arduino nothing happens as described?
    • .I was wondering a few things that I might have wrong:
      • Do I have the proper jumper wire connections?
        • Is 10.0 the RX pin I'm using?
      • Do I have the proper pins defined in uart_task.h ?
      • Is your example code portable to the Arduino Nano 33 IoT? or do I need to do something different?
      • You use the 10.0 pin on your PSoc6 CY8CPROTO kit. What is the equivalent pin on the PSoC6 CY8CKIT?

    Thanks so much for an excellent project and all you continued help.

    Steve K

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
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