Архив рубрики: Новости
STM32F4 MicroPython SD-Card
Библиотека тут: https://github.com/micropython/micropython/tree/master/drivers/sdcard
Подключили на SPI2 (CS, SCK, MISO, MOSI) = (Y5, Y6, Y7, Y8) = (PB12, PB13, PB14, PB15)
Модуль 1.8 inch SPI TFT LCD Display Module ST7735 128×160 (Aliexpress)
Board STM32F407 Discovery with MicroPython
- http://micropython.org – (STM32F4-MicroPython – Загрузить прошивку.)
- https://github.com/micropython/micropython/wiki/Board-STM32F407-Discovery
- Setup MicroPython on STM32F407 Discovery Board
- Using Micro Python and pyboard with Windows
- A collection of modules and examples for MicroPython running on an STM32F4DISCOVERY board
- Micropython-Samples GitHub (Library)
- Hacking an SD-Card to Micro Python on STM32F4-Discovery
- STM32F407VG 168MHz (100pin)
- 1024KB flash ROM, 192KB RAM
- 3axis accelerometer LIS302DL or LIS3DSH (Depending on which revision Discovery board you have)
- mems microphopne MP45DT02, audio amp CS43L22
- 4 user LEDs
- 1 user switch
- Reset switch
- USB OTG
Проверенно все работает (Под Windows 7/8/10) все прошивается. После прошивки убрать только
- BOOT0<->VDD. Только для прошивки через CN5. (DfuSE USB Programming)
- PA9<->5V Оставить.
- для того чтобы скомпилить с Ethernet модулем make -B BOARD=STM32F4DISC MICROPY_PY_WIZNET5K=5500 (как проверю работоспособность – отпишу)
>> dir(network)
[‘__class__’, ‘__name__’, ‘WIZNET5K’, ‘route’]
>>>
Простой пример с выходом по синей кнопке.
# main.py -- put your code here!
from machine import Pin
p2 = Pin('PA0', Pin.IN) # Buttom BLUE
while 1:
if p2.value() == 1:
break
print('Done')
from machine import Pin
p2 = Pin('PA0', Pin.IN) # Buttom BLUE
while 1:
if p2.value() == 1:
break
print('Done')
HDD Disk + Arduino – не очень то работает.
Драйвер для двигателей.
Источник: http://theamateurprogrammer.blogspot.com/2014/02/revitalizing-old-hard-drive-motors.html
int phase1 = 9;
int phase2 = 6;
int phase3 = 5;
int A = 9;
int B = 6;
int C = 5;
int led = 13;
unsigned long stepLength = 40000;
int minStepLength = 7000; //1400
int steps = 50;
void setup() {
pinMode(led, OUTPUT);
pinMode(phase1, OUTPUT);
pinMode(phase2, OUTPUT);
pinMode(phase3, OUTPUT);
analogWrite(led, LOW);
}
void loop() {
switchStep(1);
switchStep(2);
switchStep(3);
if(stepLength > minStepLength)
{
stepLength = stepLength - steps;
} else {
// set the minimum pulse length
stepLength=minStepLength;
}
if (stepLength < 39950) {
analogWrite(led, HIGH); // second gear
steps = 300;
}
if (stepLength < 20000) {
analogWrite(led, LOW); // third gear
steps = 50;
}
if (stepLength < 3000) {
analogWrite(led, HIGH); // fourth gear
steps = 2;
}
}
// CB, AB, AC, BC, BA, CA
void switchStep(int stage)
{
int PWM = 64;
switch(stage)
{
case 1:
analogWrite(phase1, PWM); // 100 ok
analogWrite(phase2, 0);
analogWrite(phase3, 0);
myDelay(stepLength);
break;
case 2:
analogWrite(phase1, 0);
analogWrite(phase2, PWM);
analogWrite(phase3, 0);
myDelay(stepLength);
break;
default:
analogWrite(phase1, 0);
analogWrite(phase2, 0);
analogWrite(phase3, PWM);
myDelay(stepLength);
break;
}
}
void myDelay(unsigned long p) {
if (p > 16380) {
delay (p/1000);
} else {
delayMicroseconds(p);
}
}
int phase2 = 6;
int phase3 = 5;
int A = 9;
int B = 6;
int C = 5;
int led = 13;
unsigned long stepLength = 40000;
int minStepLength = 7000; //1400
int steps = 50;
void setup() {
pinMode(led, OUTPUT);
pinMode(phase1, OUTPUT);
pinMode(phase2, OUTPUT);
pinMode(phase3, OUTPUT);
analogWrite(led, LOW);
}
void loop() {
switchStep(1);
switchStep(2);
switchStep(3);
if(stepLength > minStepLength)
{
stepLength = stepLength - steps;
} else {
// set the minimum pulse length
stepLength=minStepLength;
}
if (stepLength < 39950) {
analogWrite(led, HIGH); // second gear
steps = 300;
}
if (stepLength < 20000) {
analogWrite(led, LOW); // third gear
steps = 50;
}
if (stepLength < 3000) {
analogWrite(led, HIGH); // fourth gear
steps = 2;
}
}
// CB, AB, AC, BC, BA, CA
void switchStep(int stage)
{
int PWM = 64;
switch(stage)
{
case 1:
analogWrite(phase1, PWM); // 100 ok
analogWrite(phase2, 0);
analogWrite(phase3, 0);
myDelay(stepLength);
break;
case 2:
analogWrite(phase1, 0);
analogWrite(phase2, PWM);
analogWrite(phase3, 0);
myDelay(stepLength);
break;
default:
analogWrite(phase1, 0);
analogWrite(phase2, 0);
analogWrite(phase3, PWM);
myDelay(stepLength);
break;
}
}
void myDelay(unsigned long p) {
if (p > 16380) {
delay (p/1000);
} else {
delayMicroseconds(p);
}
}
Просмотр последних снимков со спутников NOAA
#!/usr/bin/python
import os, syslog,io
import pygame, re
import time
import pywapi
import string
import requests
import datetime
try:
# Python2
from urllib2 import urlopen
except ImportError:
# Python3
from urllib.request import urlopen
#!/usr/bin/python
import os, syslog
import pygame
import time
import pywapi
import string
import os
import io
BLACK = (0,0,0)
WHITE = (255,255,255)
GREEN = (0,255,0)
RED = (255,0,0)
BLUE = (0,0,255)
SCREEN_WIDTH = 320
SCREEN_HEIGHT = 240
os.putenv('SDL_FBDEV', '/dev/fb1')
os.putenv('SDL_MOUSEDRV', 'TSLIB')
os.putenv('SDL_MOUSEDEV', '/dev/input/touchscreen')
pygame.display.init()
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
screen.fill((0, 0, 0))
pygame.font.init()
pygame.display.update()
pygame.mouse.set_visible(False)
fontpath = pygame.font.match_font('dejavusansmono')
font = pygame.font.Font(fontpath, 20)
fontSm = pygame.font.Font(fontpath, 18)
font_big = pygame.font.Font(None, 50)
font_small = pygame.font.Font(None,30)
ok = True
while ok:
url = 'http://sat.pajero4x4.ru/?image=last'
try:
data = requests.get(url=url)
except:
print "Error Request"
time.sleep(10)
else:
if data.status_code == 200:
if re.search('jpg#',data.text):
noaa = data.text.split("\n")
f,d = noaa[-1].split("#")
image_url = "http://sat.pajero4x4.ru/NOAA/" + f
try:
image_str = urlopen(image_url).read()
except HTTPError as e:
print "Error url..."
else:
image_file = io.BytesIO(image_str)
logo = pygame.image.load(image_file).convert()
logo = pygame.transform.scale(logo,( SCREEN_WIDTH, SCREEN_HEIGHT))
screen.blit(logo, (0, 0))
text = font_small.render('%s'%d, True,RED)
screen.blit(text,(5,220))
pygame.display.update()
else:
print "Error"
time.sleep(10)
print "Reload"
print(datetime.datetime.now())
import os, syslog,io
import pygame, re
import time
import pywapi
import string
import requests
import datetime
try:
# Python2
from urllib2 import urlopen
except ImportError:
# Python3
from urllib.request import urlopen
#!/usr/bin/python
import os, syslog
import pygame
import time
import pywapi
import string
import os
import io
BLACK = (0,0,0)
WHITE = (255,255,255)
GREEN = (0,255,0)
RED = (255,0,0)
BLUE = (0,0,255)
SCREEN_WIDTH = 320
SCREEN_HEIGHT = 240
os.putenv('SDL_FBDEV', '/dev/fb1')
os.putenv('SDL_MOUSEDRV', 'TSLIB')
os.putenv('SDL_MOUSEDEV', '/dev/input/touchscreen')
pygame.display.init()
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
screen.fill((0, 0, 0))
pygame.font.init()
pygame.display.update()
pygame.mouse.set_visible(False)
fontpath = pygame.font.match_font('dejavusansmono')
font = pygame.font.Font(fontpath, 20)
fontSm = pygame.font.Font(fontpath, 18)
font_big = pygame.font.Font(None, 50)
font_small = pygame.font.Font(None,30)
ok = True
while ok:
url = 'http://sat.pajero4x4.ru/?image=last'
try:
data = requests.get(url=url)
except:
print "Error Request"
time.sleep(10)
else:
if data.status_code == 200:
if re.search('jpg#',data.text):
noaa = data.text.split("\n")
f,d = noaa[-1].split("#")
image_url = "http://sat.pajero4x4.ru/NOAA/" + f
try:
image_str = urlopen(image_url).read()
except HTTPError as e:
print "Error url..."
else:
image_file = io.BytesIO(image_str)
logo = pygame.image.load(image_file).convert()
logo = pygame.transform.scale(logo,( SCREEN_WIDTH, SCREEN_HEIGHT))
screen.blit(logo, (0, 0))
text = font_small.render('%s'%d, True,RED)
screen.blit(text,(5,220))
pygame.display.update()
else:
print "Error"
time.sleep(10)
print "Reload"
print(datetime.datetime.now())