Motor and LCD Shield conflicting

Discussion related to "under the hood" OpenMV topics.
anacoda
Posts: 3
Joined: Fri Aug 16, 2019 5:10 pm

Motor and LCD Shield conflicting

Postby anacoda » Fri Aug 16, 2019 5:24 pm

If I initialize the LCD shield and try to do PWM with the motor shield as well, it behaves strangely running one of the motors at what seems to be full speed. Are there any conflicting pins? How can I fix this?

Thanks,

Ana
User avatar
iabdalkader
Posts: 991
Joined: Sun May 24, 2015 3:53 pm

Re: Motor and LCD Shield conflicting

Postby iabdalkader » Fri Aug 16, 2019 5:59 pm

Yes the motor and LCD shields have common pins, you can't use them both at the same time.
anacoda
Posts: 3
Joined: Fri Aug 16, 2019 5:10 pm

Re: Motor and LCD Shield conflicting

Postby anacoda » Fri Aug 16, 2019 6:02 pm

Is there any workaround? I know there are other free pins I could use for the motor shield PWM and direction than are used by the LCD, just not sure if there are enough.
User avatar
iabdalkader
Posts: 991
Joined: Sun May 24, 2015 3:53 pm

Re: Motor and LCD Shield conflicting

Postby iabdalkader » Fri Aug 16, 2019 6:14 pm

No, unfortunately the LCD shields needs a lot of pins most of which are shared with the motor shields, and it leaves only 1 free PWM channel.
ScottM
Posts: 62
Joined: Thu May 30, 2019 2:12 pm
Location: Ottawa, Canada

Re: Motor and LCD Shield conflicting

Postby ScottM » Sat Aug 17, 2019 9:04 am

There is a workaround if you don't mind adding more hardware. Connect the LCD shield to the camera and use a couple of the unused pins from the camera to send commands to an Arduino Nano or UNO and have it drive the motor(s). For example, P4 and P5 are free and they are serial (UART) pins, so you can send PWM numbers to the Arduino and have it interpret them and drive the motor. I am using a 4 line LCD display connected to an Arduino Mega to display status updates from the H7 camera. I use a serial link.
Cat
Posts: 15
Joined: Mon Aug 19, 2019 12:05 pm

Re: Motor and LCD Shield conflicting

Postby Cat » Mon Aug 19, 2019 12:31 pm

Hi there, I'm Cat and working with Ana on the same project.

I found that the debug connector has 2 pins that can be used as GPIO (PA13, PA14 on SWCLK and SWDIO).
Also, there are some un-soldered pins (24, 25) that are TIM2_Ch2/3 or something like that so I could use for PWM if somehow I can solder to them.
I think the current timer used is Tim4 so there should be no conflict

Which file(s) do I need to modify to give micro-pithon access to those? Can you do it? Others would benefit without negative impact.
It would take me a while to set the IDE and compiler up.

Thanks and best,

Cat
User avatar
kwagyeman
Posts: 3435
Joined: Sun May 24, 2015 2:10 pm

Re: Motor and LCD Shield conflicting

Postby kwagyeman » Mon Aug 19, 2019 3:28 pm

Me and Ibrahim have like zero time to focus on small adds like this. We really need our users to support the open source project but sending in commits to enable things like this.

As for the GPIOs to enable these... Um, it's not that easy. Direct HAL access is easy but MicroPython has a lot of code layers on this stuff making it not straight forward. I'd recommend using another Microcontroller for I/O that you just talk serial to the OpenMV Cam with. This will be faster.
Nyamekye,
Cat
Posts: 15
Joined: Mon Aug 19, 2019 12:05 pm

Re: Motor and LCD Shield conflicting

Postby Cat » Mon Aug 19, 2019 4:13 pm

I'm confused: it's a small add but you don't have time for it?

And it's small but with many code layers? And you can't even tell me which files I need to edit?

I want to use your OpenMV in a product. If I add another uC it increases the cost a lot; it's not an option.

I bought it because, among other things it had the LCD and motor shields. I didn't see anywhere they don't work together.
I found which pins can be used so you; knowing your product/code; could enable them in, probably, less than an hour.

Please do.

Cat
User avatar
kwagyeman
Posts: 3435
Joined: Sun May 24, 2015 2:10 pm

Re: Motor and LCD Shield conflicting

Postby kwagyeman » Mon Aug 19, 2019 4:54 pm

Hi Cat, I have a day job and don't get much time to actually write code anymore because I have to answer various help support emails along with other things in my time to run the OpenMV project. Depending on me to modify the firmware to support this type of stuff was fine when the project started but generally it gets stalled now since I'm too busy.

As for the files to modify. I don't actually know exactly. Ibrahim deals with the MicroPython base code. I wrote a lot of the image processing code and that's where I have more experience.

I'll ping Ibrahim and see if he can do something for you. He's in the middle of moving right now however...
Nyamekye,
User avatar
kwagyeman
Posts: 3435
Joined: Sun May 24, 2015 2:10 pm

Re: Motor and LCD Shield conflicting

Postby kwagyeman » Mon Aug 19, 2019 4:57 pm

Note that the STM32 registers are directly accessible via python using the stm module.

You can so:

import stm

stm.mem32[0x........] = ...

To directly set a register in RAM. Using this you can do direct GPIO control by looking up the correct registers in the STM32H7 reference manual.

Doing anything more than GPIO control is probably too complex however beyond this.
Nyamekye,
User avatar
kwagyeman
Posts: 3435
Joined: Sun May 24, 2015 2:10 pm

Re: Motor and LCD Shield conflicting

Postby kwagyeman » Mon Aug 19, 2019 5:03 pm

Mmm, this file might be it: https://github.com/openmv/micropython/b ... 4/pins.csv

It's in the MicroPython submodule in the main firmware. Adding the new pins to it should create the Python parts when you do a rebuild of the firmware.

You can find the build instructions under the wiki on the OpenMV firmware GitHub.
Nyamekye,
User avatar
iabdalkader
Posts: 991
Joined: Sun May 24, 2015 3:53 pm

Re: Motor and LCD Shield conflicting

Postby iabdalkader » Mon Aug 19, 2019 7:39 pm

I bought it because, among other things it had the LCD and motor shields. I didn't see anywhere they don't work together.
The pin mappings of every shield is in the product page, we have a limited number of I/Os it makes sense that some shields will share pins. However we'll make sure this info is mentioned.
I found that the debug connector has 2 pins that can be used as GPIO (PA13, PA14 on SWCLK and SWDIO).
I think SWCLK and SWDIO have some limitations on being used as GPIOs, you have to check the datasheet first.
I want to use your OpenMV in a product. If I add another uC it increases the cost a lot; it's not an option.
If you're just doing a prototype for a product, you could use another micro-controller/chip to control the motors as it will not be part of your final product. Plus any changes made to enable pins will not be merged in the upstream firmware.

Alternatively, you could try something like this, it's a serial ("smart") LCD, it will be much slower but it should free a lot of pins.

https://www.sparkfun.com/products/11377
Cat
Posts: 15
Joined: Mon Aug 19, 2019 12:05 pm

Re: Motor and LCD Shield conflicting

Postby Cat » Mon Aug 19, 2019 9:33 pm

This is not great.

1. The project seemed to have good support. New HW, etc. I didn't read anywhere that support is going down because of a day job. It's understandable but it should have been mentioned.

2. It's nice that registers can be set but setting up a timer by doing that seems like a big pain. Much bigger than re-doing what's already been done in source code, by somebody that's done it already for other pins/timer. OR at least say where.

3. RE "pins.csv": iabdalkader should be able to tell me if it would be enough to add lines there for P10-13 with PA13, PA14 etc. I suspect it's not. What else?

4. You say "Plus any changes made to enable pins will not be merged in the upstream firmware." I think any changes YOU make could and should make it.
Why not? They wouldn't break anything.
And, you could add some Test-Points to some/most unused pins to make it easier for them to be used by anybody that doesn't have enough pins.

5, I think it's wrong to add new/different HW and have to write new code for another display when existing HW is totally capable of doing what's needed, if only one could do a little more of what he's done already: You already did set PWM up on some pins so it should be trivial to add that to other pins AND keep it there. And the GPIO either on the pins I mentioned or other unused pins.

Thanks,

Cat
User avatar
kwagyeman
Posts: 3435
Joined: Sun May 24, 2015 2:10 pm

Re: Motor and LCD Shield conflicting

Postby kwagyeman » Mon Aug 19, 2019 11:12 pm

Hi Cat, I'll sit down and try to get you a firmware image tonight with new GPIO pins added.

A question however, I've never used any other product where I got support tickets answered the day of by the creator and feature requests considered. I don't understand your expectation that your request would be serviced at all. By all accounts we should stop responding to you and not help you given your attitude.

For example, if I ask for something on MicroPython Damien is generally too busy to answer timely or really do anything other than make a simple suggestion.

Similarly, if I asked something on Arduino's forum Banzi would never answer it.
Nyamekye,
User avatar
kwagyeman
Posts: 3435
Joined: Sun May 24, 2015 2:10 pm

Re: Motor and LCD Shield conflicting

Postby kwagyeman » Mon Aug 19, 2019 11:28 pm

K, I'll added support for the GPIOs and leave notes here on what I did to do it. I think I should be able to add more PWM too and I'll add notes for that too. It's all changes to MP code so it shouldn't be too hard. They autogenerate a lot of stuff and there's no documentation on it... So, I just have to figure it out.
Nyamekye,
Cat
Posts: 15
Joined: Mon Aug 19, 2019 12:05 pm

Re: Motor and LCD Shield conflicting

Postby Cat » Tue Aug 20, 2019 12:23 am

I appreciate it.
I didn't expect support same day.
But I did expect support, as I saw support being given in the past and that was a big plus.
There are cheaper cameras out there with more powerful processors but I chose yours because it seemed you're "close", I don't know how to say this.
I think my attitude started nice enough; I agree it didn't stay that way but I think you may see why.

Thanks again,

Cat
User avatar
kwagyeman
Posts: 3435
Joined: Sun May 24, 2015 2:10 pm

Re: Motor and LCD Shield conflicting

Postby kwagyeman » Tue Aug 20, 2019 12:30 am

Please understand I answer most of these support questions on my phone during work. I'm not in font of my OpenMV development computer. This limits what I can respond with.
Nyamekye,
User avatar
kwagyeman
Posts: 3435
Joined: Sun May 24, 2015 2:10 pm

Re: Motor and LCD Shield conflicting

Postby kwagyeman » Tue Aug 20, 2019 1:19 am

Okay,

Addding:

P10,PD15
P11,PA13
P12,PA14
P13,PA0
P14,PA1
P15,PA2
P16,PA3

To:

https://github.com/openmv/micropython/b ... 4/pins.csv

Makes the new pins available. You can toggle them and whatever now.

This also enabled you to use timer 5 for PWM on pins PA0/1/2/3:

Code: Select all

# PWM Control Example
#
# This example shows how to do PWM with your OpenMV Cam.

import time
from pyb import Pin, Timer

tim = Timer(5, freq=1000) # Frequency in Hz
# Generate a 1KHz square wave on TIM4 with 50% and 75% duty cycles on channels 1 and 2, respectively.
ch1 = tim.channel(1, Timer.PWM, pin=Pin("P13"), pulse_width_percent=50)
ch2 = tim.channel(2, Timer.PWM, pin=Pin("P14"), pulse_width_percent=75)
ch3 = tim.channel(3, Timer.PWM, pin=Pin("P15"), pulse_width_percent=75)
ch4 = tim.channel(4, Timer.PWM, pin=Pin("P16"), pulse_width_percent=75)

while (True):
    time.sleep(1000)
Finally, I updated the servo code:

https://github.com/openmv/micropython/b ... 32/servo.c

To support 4 servo channels - i.e. PD15 (P10).

Code: Select all

# Servo Control Example
#
# This example shows how to use your OpenMV Cam to control servos.

import time
from pyb import Servo

s1 = Servo(1) # P7
s2 = Servo(4) # P8

while(True):
    for i in range(1000):
        s1.pulse_width(1000 + i)
        s2.pulse_width(1999 - i)
        time.sleep(10)
    for i in range(1000):
        s1.pulse_width(1999 - i)
        s2.pulse_width(1000 + i)
        time.sleep(10)
Ibrahim may wish to roll these changes into the default release so that they are just there.

To load the firmware just (while not connected to the camera) do Tools -> Run Bootloader and select the firmware.bin file. The file is for the H7.
Attachments
firmware.zip
(971.48 KiB) Downloaded 90 times
Nyamekye,
Cat
Posts: 15
Joined: Mon Aug 19, 2019 12:05 pm

Re: Motor and LCD Shield conflicting

Postby Cat » Tue Aug 20, 2019 2:13 pm

Thank you very much; I'll try these.

Cat
Cat
Posts: 15
Joined: Mon Aug 19, 2019 12:05 pm

Re: Motor and LCD Shield conflicting

Postby Cat » Tue Aug 20, 2019 4:07 pm

Was it enough to add the pins to the CSV to get all Alternate Functionality?
That seems amazing.
How did it choose TIM5 for PWM when it could have chosen Tim2?

Thanks again,

Cat
Cat
Posts: 15
Joined: Mon Aug 19, 2019 12:05 pm

Re: Motor and LCD Shield conflicting

Postby Cat » Tue Aug 20, 2019 4:32 pm

Sorry, I think I asked something "stupie".
So far Ana's done all coding for this; I usually do the HW.
I just noticed in an example that I do get to choose the timer myself.
WOW! Very nice if all that needs doing is adding the pins to the CSV.

Thanks again.

Cat
Cat
Posts: 15
Joined: Mon Aug 19, 2019 12:05 pm

Re: Motor and LCD Shield conflicting

Postby Cat » Tue Aug 20, 2019 5:01 pm

I can confirm that A13 and A14 (P11, P12) on the debug connector work as expected as GPIOs.
So you can improve your written specs eh?

Cat

PS - Soldering to the other pins will be a pita... I hope you'll consider improving that with as many test points as you can fit whenever you do another spin.
User avatar
iabdalkader
Posts: 991
Joined: Sun May 24, 2015 3:53 pm

Re: Motor and LCD Shield conflicting

Postby iabdalkader » Tue Aug 20, 2019 5:12 pm

WOW! Very nice if all that needs doing is adding the pins to the CSV.
Thanks again.
Glad we could help!
4. You say "Plus any changes made to enable pins will not be merged in the upstream firmware." I think any changes YOU make could and should make it.
Why not? They wouldn't break anything.
Sure, but in the mean time please feel free to fork the project and merge in whatever changes you want in your own repo.
I can confirm that A13 and A14 (P11, P12) on the debug connector work as expected as GPIOs.
So you can improve your written specs eh?

Cat

PS - Soldering to the other pins will be a pita... I hope you'll consider improving that with as many test points as you can fit whenever you do another spin.
We will consider that in the next revision, thanks for the suggestions.
Cat
Posts: 15
Joined: Mon Aug 19, 2019 12:05 pm

Re: Motor and LCD Shield conflicting

Postby Cat » Tue Aug 20, 2019 5:35 pm

About that... " please feel free to fork the project and merge in whatever changes you want in your own repo":

It's not that I don't want to.
But, among other things, kwagyeman said he also did something for the servo code.
So I feel like it's better to include his changes than whatever I might do (the CSV file only, really).

If that's wrong... I'll do whatever you ask.

Thanks,

Cat
Cat
Posts: 15
Joined: Mon Aug 19, 2019 12:05 pm

Re: Motor and LCD Shield conflicting

Postby Cat » Wed Aug 21, 2019 12:29 am

I think I have a plan; please tell me if you see anything wrong with it
So I need 4 GPIOs and 2 PWMs.
It's going to be hard to solder straight to microcontroller pins so I can almost avoid it by using pads from existing components.
For the GPIOs I can use 2 from the debug connector and 2 from LEDs (R,G,B,IR) I definitely don't use IR and please recommend if any color is less meaningfull, in case I disconnect it from LED (I could keep it connected).
For PWM I have P9 and it should be easiest to solder a wire to the corner pin 25 that is TIM2_CH4 or TIM5_CH4 or TIM15_CH2. Which timers are already used? I like 2, it's fancy, but that's a good reason for it to be already in use.
I could use the LCD backlight too (disconnect it on LCD board) , it's connected to Tim2_Ch1 and Tim8_Ch1N.

Please advise if any of these timers are already in use or any of my plan is wrong for some reason.

Thanks,

Cat
User avatar
kwagyeman
Posts: 3435
Joined: Sun May 24, 2015 2:10 pm

Re: Motor and LCD Shield conflicting

Postby kwagyeman » Wed Aug 21, 2019 12:56 am

Timer1 is the only one that's necessary for the camera. 5 and 4 are available for PWM. Timer 2 is available to. I don't know about the other timers. We borrow a lot of code from MicroPython that kinda just works so I can't say exactly what's in use and not beyond the ones that are obviously used by us. Most likely they are free as the pyboard we are based on tries to provide as many resources as it can for the user.

For LEDs, the bootloader uses the green one, file system access via the comp is red, and blue is the heart beat led for the main.py script. Blue would be the least important.

Anyway, with the LEDs and the debug pins you should have 4 GPIOs. Then the PWM pins can come from P9 and and pin 25.
Nyamekye,
Cat
Posts: 15
Joined: Mon Aug 19, 2019 12:05 pm

Re: Motor and LCD Shield conflicting

Postby Cat » Thu Oct 03, 2019 12:47 pm

This all works now; we have LCD and motor shield working happily together; THANK YOU!

Did the changes make it into the ... main "stream" or whatever it's called, so that things will still work if I use the IDE FW updater?

Thanks and best,

Cat
User avatar
kwagyeman
Posts: 3435
Joined: Sun May 24, 2015 2:10 pm

Re: Motor and LCD Shield conflicting

Postby kwagyeman » Thu Oct 03, 2019 2:38 pm

No, they didn't. Um, can you jog my memory on what you need again? It's pretty easy to just break out the pins.
Nyamekye,
Cat
Posts: 15
Joined: Mon Aug 19, 2019 12:05 pm

Re: Motor and LCD Shield conflicting

Postby Cat » Thu Oct 03, 2019 5:06 pm

I think it's all above, but here it is:
Addding:
P10,PD15
P11,PA13
P12,PA14
P13,PA0
P14,PA1
P15,PA2
P16,PA3

I think this also enables (if needed) PWM on the pins I need; I'm using:
PWM_MOT_A_L = [4, 3, "P9"]
PWM_MOT_B_R = [2, 1, "P6"]
(I was going to use some other PWM until I noticed that (I think) LCD LED can to PWM so I'm using that)

You also said:
"Finally, I updated the servo code:
https://github.com/openmv/micropython/b ... 32/servo.c
To support 4 servo channels - i.e. PD15 (P10)."

Thank you,
Cat
Cat
Posts: 15
Joined: Mon Aug 19, 2019 12:05 pm

Re: Motor and LCD Shield conflicting

Postby Cat » Tue Oct 08, 2019 8:04 pm

Would you please let me know when it's safe to use the updater?
I.E. when the changes are in the trunk or whatever terminology you use?

Thanks,

Cat
User avatar
kwagyeman
Posts: 3435
Joined: Sun May 24, 2015 2:10 pm

Re: Motor and LCD Shield conflicting

Postby kwagyeman » Tue Oct 08, 2019 9:43 pm

Sorry, this hasn't been high priority for me. Um, I can do it tonight. I'll send a PR. Ibrahim's on a finishing trip so I'll just make you a firmware drop.
Nyamekye,
User avatar
kwagyeman
Posts: 3435
Joined: Sun May 24, 2015 2:10 pm

Re: Motor and LCD Shield conflicting

Postby kwagyeman » Wed Oct 09, 2019 2:44 am

Hi Cat, the PR for what you asked for is here:

https://github.com/openmv/micropython/pull/59

Attached is an H7 firmware bin file with the latest fixes.
Attachments
firmware.zip
(982.86 KiB) Downloaded 8 times
Nyamekye,
Cat
Posts: 15
Joined: Mon Aug 19, 2019 12:05 pm

Re: Motor and LCD Shield conflicting

Postby Cat » Tue Oct 15, 2019 4:26 pm

Thank you.
This is great for now but I'm still worried about the future eh.
I'm hesitating what to ask; I don't want to waste your time, but I do feel there's no downside to adding the changes to the trunk when Ibrahim is back.
So... is he back?
Are the changes in the trunk?
Thanks again,

Cat
User avatar
kwagyeman
Posts: 3435
Joined: Sun May 24, 2015 2:10 pm

Re: Motor and LCD Shield conflicting

Postby kwagyeman » Tue Oct 15, 2019 4:58 pm

Changes are in the main repo now.
Nyamekye,
User avatar
kwagyeman
Posts: 3435
Joined: Sun May 24, 2015 2:10 pm

Re: Motor and LCD Shield conflicting

Postby kwagyeman » Tue Oct 15, 2019 4:58 pm

Nyamekye,
Cat
Posts: 15
Joined: Mon Aug 19, 2019 12:05 pm

Re: Motor and LCD Shield conflicting

Postby Cat » Tue Oct 29, 2019 12:42 pm

YEEEEEEY! Thank you!

Return to “Technical Discussion”

Who is online

Users browsing this forum: MSN [Bot] and 6 guests