Page 15 of 15

Re: MCUDev Black STM32F407VET6 + STM32F407ZET6 dev boards

Posted: Fri Feb 14, 2020 2:58 am
by Sniper
Here are the pin diagram/infographic layout from my Google Drive hope it will come to any use!

https://drive.google.com/drive/folders/ ... sp=sharing

Re: MCUDev Black STM32F407VET6 + STM32F407ZET6 dev boards

Posted: Fri Feb 14, 2020 3:22 am
by mcauser
Hi @Sniper.
Is this necessary in the code? import machine and import time, import Pin?
Unless your boot.py or main.py imports machine, you'll need to do it before you can use it. Otherwise you'll get a NameError.

import time lets you use time.sleep(). Without it, time won't exist (in the variable sense). Again, if it's in your boot or main.py, it's already imported. You can see what is imported by running dir().

You don't need to import Pin. It does not exist. Pin is a class inside machine. You get it when you import machine (all of machine) and is accessible as machine.Pin.

An alternate syntax which lets you import some of machine is: from machine import Pin, I2C.
If you use this syntax, machine.Pin doesn't exist. It's just Pin, so you'll need to remove the "machine." prefixes below.

Code: Select all

import machine
import time

# relay 1
p = machine.Pin.cpu.PE0
p.init(mode=machine.Pin.OUT)
p.value(0)
time.sleep(2)
p.value(1)

# relay 2
p = machine.Pin.cpu.PE1
p.init(mode=machine.Pin.OUT)
p.value(0)
time.sleep(2)
p.value(1)
If you change import machine to from machine import Pin, you'll need to replace all machine.Pin occurrences below with just Pin.

Same goes for time.sleep. If you from time import sleep, then you can just call sleep(2) below.

Re: MCUDev Black STM32F407VET6 + STM32F407ZET6 dev boards

Posted: Fri Feb 14, 2020 1:29 pm
by Sniper
mcauser wrote:
Fri Feb 14, 2020 3:22 am
Hi @Sniper.
Is this necessary in the code? import machine and import time, import Pin?
Unless your boot.py or main.py imports machine, you'll need to do it before you can use it. Otherwise you'll get a NameError.

import time lets you use time.sleep(). Without it, time won't exist (in the variable sense). Again, if it's in your boot or main.py, it's already imported. You can see what is imported by running dir().

You don't need to import Pin. It does not exist. Pin is a class inside machine. You get it when you import machine (all of machine) and is accessible as machine.Pin.

An alternate syntax which lets you import some of machine is: from machine import Pin, I2C.
If you use this syntax, machine.Pin doesn't exist. It's just Pin, so you'll need to remove the "machine." prefixes below.

Code: Select all

import machine
import time

# relay 1
p = machine.Pin.cpu.PE0
p.init(mode=machine.Pin.OUT)
p.value(0)
time.sleep(2)
p.value(1)

# relay 2
p = machine.Pin.cpu.PE1
p.init(mode=machine.Pin.OUT)
p.value(0)
time.sleep(2)
p.value(1)
If you change import machine to from machine import Pin, you'll need to replace all machine.Pin occurrences below with just Pin.

Same goes for time.sleep. If you from time import sleep, then you can just call sleep(2) below.
I still can get the code run, nothing happens.
this is what is in my boot.py

Code: Select all

# boot.py -- run on boot-up
# can run arbitrary Python, but best to keep it minimal

import machine
import pyb
pyb.country('US') # ISO 3166-1 Alpha-2 code, eg US, GB, DE, AU
#pyb.main('main.py') # main script to run after this one
#pyb.usb_mode('VCP+MSC') # act as a serial and a storage device
#pyb.usb_mode('VCP+HID') # act as a serial device and a mouse
and this is the code for 8 channel relay. but it wont run as expected.

Code: Select all

# 8 Channel Relay Module

import machine
import time

#Relay Nr.1

p = machine.Pin.cpu.PE0
p.init(mode=machine.Pin.OUT)
p.value(0)
time.sleep(2)
p.value(1)

# relay 2

p = machine.Pin.cpu.PE1
p.init(mode=machine.Pin.OUT)
p.value(0)
time.sleep(2)
p.value(1)

#Relay Nr.3

p = machine.Pin.cpu.PE2
p.init(mode=machine.Pin.OUT)
p.value(0)
time.sleep(2)
p.value(1)

#Relay Nr.4

p = machine.Pin.cpu.PE3
p.init(mode=machine.Pin.OUT)
p.value(0)
time.sleep(2)
p.value(1)

#Relay Nr.5

p = machine.Pin.cpu.PE4
p.init(mode=machine.Pin.OUT)
p.value(0)
time.sleep(2)
p.value(1)

#End of the code!

Re: MCUDev Black STM32F407VET6 + STM32F407ZET6 dev boards

Posted: Fri Feb 14, 2020 6:38 pm
by Sniper
Can you please tell where and how a newbie like me can read and learn about how to program this boards for absolute beginners.