element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • 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
Sixth Sense Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Sixth Sense Design Challenge
  • More
  • Cancel
Sixth Sense Design Challenge
Blog R2B4 #8 - STM32F411RE-Nucleo Coding
  • Blog
  • Forum
  • Documents
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: 14rhb
  • Date Created: 9 Mar 2019 6:02 PM Date Created
  • Views 356 views
  • Likes 8 likes
  • Comments 14 comments
  • l298
  • sixth_sense
  • r2b4
  • robot
  • stepper motors
  • nema17
  • sixth sense design challenge
Related
Recommended

R2B4 #8 - STM32F411RE-Nucleo Coding

14rhb
14rhb
9 Mar 2019

      • 1.     Aims
      • 2.     Code to Make R2B4 Move
      • 3.    The Code, Functions and Hardware Operation
        • 3.1     Navigation
        • 3.2  Getting TE Sensor (KMT32B) into Nucleo
        • 3.3.     Driving the motor from Nucleo
        • 3.4    R2B4 Kind of Worked (for a while)
      • 4.     What Next ?

1.     Aims

I wanted to merge the HAL code from my working SensorTile app into the example Datalog code but after many days of effort I was still not successful - to me this task is quite tricky. Unfortunately I could also not simply add in the UART5 to the original SensorTile Datalog example as the STM32CubeMX project code is not available. My choices are (1) to keep going and perhaps run out of time or (2) make R2B4 use another sensor - the TE connectivity magnetometer. This might work and I have seen some of the great functionality that the SensorTile can provide but unfortunately I cannot utilise it at this stage. Therefore I'm going to progress option 2 for now.

 

2.     Code to Make R2B4 Move

To make R2B4 navigate a course other than a straightline requires a few way points like show below:

For three waypoints I will need to know the three distances to travel and the three angles to turn R2B4 by. The distances should be easy to work out using the stepper motors as a rough estimate - however if the wheels slip then the error margin will increase in time. The angles were to be read from the SensorTile data and UART. Now I will try and utilise the TE Connectivity Magnetometer to achieve the same - coupling this sensor directly into my STM32F411RE-Nucleo board.

 

To achieve the above I will need a controlling loop, a function for distance and a function for turning to a specific angle.

 

When R2B4 arrives at the destination it will offload the cargo of sand or pebbles and then retrace the route - again this should not be too difficult in C code.

 

 

3.    The Code, Functions and Hardware Operation

3.1     Navigation

 

I have written my software to utilise a linked list (pointers) where each node is a command. The commands are stop, turn or move and the parameters around each are optional. This command list is traversed to obtain each command, executing them in sequence. At the end the load will be dropped off and the R2B4 will retrace its route using the same list in reverse.

 

typedef struct _Command{
  commandTypes thisCommand;
  uint16_t turnAngle;
  uint16_t moveDistance;
  uint8_t moveSpeed;
  struct _Command* nextCommand;
}command;

 

Functions are:

void cmdMotorsStop(void);
void cmdMotorsTurn(commandTypes ,uint16_t turnAngle);
void cmdMotorsDrive(commandTypes ,uint16_t moveDistance,uint16_t moveSpeed);

Where commandTypes is an enumerated type to show left, right, forward, backward or stop

 

I can then build, add or modify a list of commands like this:

  command *myCommandList;
  command *myCommandListStart=myCommandList;
  myCommandList = addCmd(stop,0,0,0);
  myCommandList = addCmd(forward,0,100,medium);
  myCommandList = addCmd(left,30,0,0);
  myCommandList = addCmd(forward,0,100,medium);

I've made a copy of the initial pointer as I wish to jump back to it if the R2B4 is reset or an error occurs.

 

The main forward pass through the list will look something like this:

      while(startToFinish==1){
        while(myCommandList->nextCommand != NULL){
            switch(myCommandList->thisCommand){
            case (stop):
                cmdMotorsStop();
                break;
            case (left):
                cmdMotorsTurn(left,myCommandList->turnAngle);
                break;
            case (right):
                cmdMotorsTurn(right,myCommandList->turnAngle);
                break;
            case (forward):
                cmdMotorsDrive(forward,myCommandList->moveDistance,myCommandList->moveSpeed);
                break;
            case (backward):
                cmdMotorsDrive(backward,myCommandList->moveDistance,myCommandList->moveSpeed);
                break;
            default:
                cmdMotorsStop();
                break;
            }
            myCommandList++;
        }
        startToFinish=0;
      }

 

3.2  Getting TE Sensor (KMT32B) into Nucleo

There is one problem with using this sensor....it is very small. It utilises the 8-WFDFN package and my thoughts are do I try making a PCB or should I mount it deadbug style ? Either will be difficult I feel. Then as I started to read more about this unit I stated to have doubts if it was for measuring the earth's magnetic field. I think it is mainly intended for placing a magnet near and then being able to measure the angle of rotation in that field.  Maybe there is a second problem with this approach then. Maybe I could use a magnetic plate at each node where I want R2B4 to turn ?

For now, as an interim step I am going to 'open-loop' drive R2B4 to get it to turn. If I work out a mechanism to get angle data into R2B4 then I will add that later.

 

3.3.     Driving the motor from Nucleo

I managed to get R2B4 to move and turn via the Arduino Uno board. I need to do the same using the STM32F411RE-Nucleo board. I need two control signals for each stepper motor, a total of four control lines. Initially I will try using my STM32CubeMX project again to regenerate my example code but this time with some extra GPIO enabled. I can test those lines using a oscilloscope or LEDs to see it I have control before making them control the direction and step rate of the two NEMA-17.

 

I added four GPIO pins as outputs in CubeMX and regenerated my code into TrueStudio: these were PC0, PC1, PC2 and PC3.

 

What happened next was really exciting (well for me it was, as a non-STM32/TrueSTudio user !). My code built without issues . It downloaded as debug/run to the STM32F411RE-Nucleo board , and then when I looked at the Morpheo pins with my oscilloscope I could see the test pattern I had generated . As far as I am concerned this is my best achievement with STM32 boards and ARM to date (I had used STM32CubeMX as intended, I had selected and set up some GPIO pins, my code had compiles, downloaded and been executed).

 

I could have connected the motors at this point but the demo code didn't command the motors to do much so I finalised the command list approach and rebuilt that.

 

Now for the final tests: I had given my command list some dummy commands - would my motors get driven as required?

3.4    R2B4 Kind of Worked (for a while)

With R2B4 jacked up in the air I had one side of the wheels turning as per my test code but the other did nothing. And then after a while it did absolutely nothing !

And then I found the actual STM32F411RE was very hot. Strangely after allowing it to cool most of my output pins still toggle as required but the MCU heats up very quickly so I guess I've damaged an output.

 

I'm not sure what I did wrong. I was using the 3.3v from the board to power my A4988 devices, but they also used +12v from the battery for the actual heavy current side.

 

Therefore I have an urgent job for tonight, that is ordering myself a new STM32F411RE-Nucleo board and hoping I don't mess that one up as well.

 

4.     What Next ?

 

In my next blog post #9 I would like to explore the TE Connectivity Load Cell - get that working and read the values into my Nucleo board. But there are many other parts of R2B4 that also need attention.

Anonymous

Top Comments

  • three-phase
    three-phase over 3 years ago +3

    Sorry to hear about the troubles you have been having. Hopefully you will get it sorted soon and move the project forward some more.

     

    Good luck.

  • 14rhb
    14rhb over 3 years ago +1

    I thought I would see what current the A4988 boards required and at 3.3v I was measuring 200mA for both although that didn't vary with the inputs which seemed good. However after some testing I think they…

  • 14rhb
    14rhb over 3 years ago in reply to 14rhb +1

    And I found my 100uF electrolytic capacitor on the power lines had slipped out of my cheap breadboard.....apparently the back EMF can damage the board without it, so I am wondering if that is why it suddenly…

  • kulky64
    kulky64 over 3 years ago in reply to 14rhb

    OK, buy yourself some good quality stepper drivers and carry on. Don't waste your time on some homebrew solutions.

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • 14rhb
    14rhb over 3 years ago in reply to kulky64

    I think you've worked out what I did wrong, thanks. I had the electrolytic on the 3.3v whereas before I used it on the 12v )and that was where I should have placed it) ! Maybe it didn't matter that it came out of the breadboard as it wasn't having the required effect anyway.

     

    Rod

    • Cancel
    • Up +1 Down
    • Reply
    • More
    • Cancel
  • kulky64
    kulky64 over 3 years ago in reply to 14rhb

    There are some ceramic caps directly on the break-out boards, so some decoupling is there. But your electrolytic capacitor would be of more help if it was connected to motor power supply instead of 3.3V rail and closer to where it is needed, not sitting in the corner of breadboard.

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • 14rhb
    14rhb over 3 years ago in reply to kulky64

    Thank you for your helpful comments - I'm sure the left hand enable was in when it all failed and I replaced with a fly-lead when testing afterwards (and forget to replace for taking the photos). I think you are right about the decoupling as well - it was a 47uF/35v across the power rails but the shorter wire had come out of the board...so effectively I had no decoupling. Maybe I had damaged the right hand module last time I used it ?

     

    Rod

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • kulky64
    kulky64 over 3 years ago in reply to 14rhb

    Hard to judge what went wrong. I was thinking why only one motor was turning; I noticed that driver on the right has ENABLE input pulled to ground by a short piece of wire, but I can't see similar wire on the left driver. There should be pull-down resistor on ENABLE pin on breakout board itself, so this probably does't explain it anyway. I wondered if power rails on your breadboard are not split in the middle, but I saw you using this breadboard on another projects, so this is probably not the case either. So who knows. Maybe insufficient decoupling or something.

    • Cancel
    • Up +1 Down
    • Reply
    • More
    • Cancel
>
Element14

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 © 2022 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

  • Facebook
  • Twitter
  • linkedin
  • YouTube