Arm Community
Arm Community
  • Site
  • User
  • Site
  • Search
  • User
Arm Community blogs
Arm Community blogs
Embedded and Microcontrollers blog Cypress Maker Lab - Barc gets a nose
  • Blogs
  • Mentions
  • Sub-Groups
  • Tags
  • Jump...
  • Cancel
More blogs in Arm Community blogs
  • AI blog

  • Announcements

  • Architectures and Processors blog

  • Automotive blog

  • Embedded and Microcontrollers blog

  • Internet of Things (IoT) blog

  • Laptops and Desktops blog

  • Mobile, Graphics, and Gaming blog

  • Operating Systems blog

  • Servers and Cloud Computing blog

  • SoC Design and Simulation blog

  • Tools, Software and IDEs blog

Tags
Actions
  • RSS
  • More
  • Cancel
Related blog posts
Related forum threads

Cypress Maker Lab - Barc gets a nose

Mark Saunders
Mark Saunders
March 23, 2017

[re-printed from PSoC Creator News and Information]

If you read my last post about Barc you will know that I was feeling pretty confident prior to the Embedded World show. All I needed to do was add some CapSense proximity loops (a.k.a. wires) to the robot, tune the CapSense sensors, and add a simple firmware state machine to move the robot based on which sensor notices a nearby hand. Simple!

And, for the most part it was. I fashioned a head for the dog from ABS plastic and taped in three loops of wire facing (pun intended) the front, left and right. I connected the wires to PSoC pins via the breadboard and got ready to finish the PSoC Creator project. Here are some pictures.

More alert readers will notice that the color of the PSoC kit has changed. More on that in a moment. Some will also see that programming the kit now requires me to feed the USB cable through the dog's mouth. Oops. That is pretty silly and, now I have done it about 600 times, I strongly advocate turning the kit around by 180 degrees. Unfortunately that would require me to rip off the breadboard and battery pack, which would make a nasty mess of the robot. I really do not want to do that… so I decided to live with it. And anyone who has tried measuring or tuning a sensitive electrical circuit like a proximity sensor will see that it is going to be tricky to get right with a big shielded cable running straight through the middle of the loop! I am, officially, a twit.

Then things got worse. My boss called. He never does that. So I knew it was likely bad news on the eve of Embedded World.

Boss: So, how is the robot car coming along?

Me:

Just fine Boss.
Boss: Will it be ready for the show? We need you talking in our theater three times day.

Me:

No problem. I am just tuning the CapSense so that the dog will chase me around the floor.
Boss: Good. I saw the last blog and it looks like you are using the PSoC 5LP kit.

Me:

Yyyyeeeessssss. And?
Boss: Well we brought out the PSoC 4 kits and they have the next generation CapSense IP.

Me:

I am building a robot dog. No-one will notice.
Boss: Well we brought out the PSoC 4 kits and they have the next generation CapSense IP.

Me:

I am building a robot dog. It has wire loops taped inside its skull. No-one will notice.
Boss: Well we brought out the PSoC 4 kits and they have the next generation CapSense IP.
Me: OK.
Boss: Good talk!

 It was very reminiscent of the famous Office Space movie and the end result was weekend work for me. The good news is that I already had a handy PSoC 4 M-series prototyping kit - a pretty red one at that - and that changing the design in PSoC Creator took less time than it took to go another round with the soldering iron. In the time-honored tradition I swapped the kits and had the design working again in about an hour, then I told the boss I worked all weekend. It's a rule…

So, for the tuning, I added a CapSense component and an EZI2C to the project. The I2C is used as a bridge between the tuning software and the target. It can update the CapSense parameters live, which really helps you iterate to a solution. In the CapSense component I set up three proximity sensors, named FRONT, LEFT sand RIGHT, and selected manual tuning.

 

 

I also turned on filtering (in the Advanced tab) to remove as much noise as possible. This turned out to be really important at the show because the noise - probably from the very static-y carpet - was way higher than on my hardwood floors at home. I shall put the full list of CapSense edits in the project file, which I will post in a blog once I finish the whole project.

Here is the C code I wrote to run the tuner. In the I2C code I just tell it about a buffer (CapSense_dsRam) in the CapSense code and the tuner program uses this to communicate with the device. To avoid a lot of silliness - chasing a robot dog around the room - I did not start the PWM while I was tuning!

 

    /* Start EZI2C component and prepare it for tuning */

    EZI2C_Start();

    EZI2C_EzI2CSetBuffer1(

        sizeof( CapSense_dsRam ),

        sizeof( CapSense_dsRam ),

        (uint8 *) &CapSense_dsRam );   

    CapSense_Start();               // Turn on CapSense   

    for(;;)

    {

        /* Start a scan and wait for it to complete */

        CapSense_ScanAllWidgets();

        while( CapSense_IsBusy() )

        {

            /* Busy loop */

        }

        CapSense_ProcessAllWidgets();   // Read all sensors and determine widget status

        CapSense_RunTuner();            // Send data to tuner (I2C)

    }

}

After building and programming I right-clicked the CapSense component and selected "Run Tuner". The tuner starts up and looks like this.

 

 

​I start tuning in the graph view. CapSense uses a "raw count" value from its sensors and it is best to set the baseline value to 80% of maximum so there is room for the counts to go up (when a hand is close) and noise is minimized. You adjust the resolution and Modulation IDAC values to make that happen. Increasing the resolution  improves the range of the sensor but also increases scan time (I do not care much in this application). Increasing the IDAC pulls the raw count value down to that 80% point.

 

 

Once I have that working I use the SNR Measurement tab. You just select the sensor and Acquire Noise. Then you put your hand by the sensor and Acquire Signal. It tells you the noise level and the SNR, which should be above 5.

 

 

I'm in good shape now. I set the Noise and negative Noise Thresholds to 5, which leaves a little wiggle room versus the measured value of 3. The Proximity threshold is 10, which is much closer to the noise than I would like, BUT I want maximum sensitivity and, if I do get some false readings it gives my dog a will of his own! I set the Touch Threshold to 100 which means that the sensor can register both proximity and, if I get really close, a touch. I might use that in the final project to change Barc's behavior in firmware.

 

 

As a sanity check I look at the Status graph, which shows the off / proximity / touch readings as I move my hand around the robot.

 

 

Once I have the settings I like I can send them To Project and quit the tuner. Back in PSoC Creator I open the parameter editor for CapSense and it lets me accept the edits from the tuner. Now, when I rebuild the program I have the tuned IDAC and threshold values for the left sensor.

 

 

I added a little code to the program, turned the PWM back on, and checked that my doggy reacts to my hand.

 

        if( CapSense_IsWidgetActive( CapSense_RIGHT_WDGT_ID ) )

        {

            PWM_Speed_WriteCompare2( 40 );

        }

        else

        {

            PWM_Speed_WriteCompare2( 0 );

        }

Here is a video of Barc sensing a hand near his face - did you notice that I actually video'd the left sensor instead of the right?

 

 IMG_1029.MOV

When I get back from vacation I will post my final Barc blog. I will complete the tuning of the other sensors and add a simple state machine to drive the motors and make him follow my hand. I will also include a bill of materials so you can re-create your own robot, with PSoC, for about $50.

Anonymous
Embedded and Microcontrollers blog
  • Formally verifying a floating-point division routine with Gappa – part 2

    Simon Tatham
    Simon Tatham
    A method of testing whether a numerical error analysis using Gappa really matches the code it is intended to describe.
    • September 4, 2025
  • Formally verifying a floating-point division routine with Gappa – part 1

    Simon Tatham
    Simon Tatham
    Learn the basics of using Gappa for numerical error analysis, using floating-point division in Arm machine code as a case study.
    • September 4, 2025
  • Adapting Kubernetes for high-performance IoT Edge deployments

    Alexandre Peixoto Ferreira
    Alexandre Peixoto Ferreira
    In this blog post, we address heterogeneity in IoT edge deployments using Kubernetes.
    • August 21, 2024