/*Example sketch to control a 28BYJ-48 stepper motor with ULN2003 driver board, and Arduino UNO. More info: https://www.makerguides.com */
// Include the Arduino Stepper Library:
#include <Stepper.h>
// Number of steps per rotation:
const int stepsPerRevolution = 2048;
//Wiring:
// Pin 8 to IN1 on the ULN2003 driver
// Pin 9 to IN2 on the ULN2003 driver
// Pin 10 to IN3 on the ULN2003 driver
// Pin 11 to IN4 on the ULN2003 driver
// Create stepper object called 'myStepper', note the pin order:
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);
void setup()
{
// Set the speed to 5 rpm:
myStepper.setSpeed(5);
// Initialize the serial port:
Serial.begin(9600);
}
void loop()
{
// Step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// Step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}
스탭모터(28BYJ48)와 스텝 모터 드라이버(ULN2003)는 저렴하고 많이 사용하고 있어서 많은 예제가 있습니다. 스탭의 반복하면서 반복 하는 시간차와 회수를 계산해서 원하는 각도로 회전하거나, 스탭의 방향에 따라서 정방향, 역방향으로 회전 시킬 수 있습니다.
IN1 = micro:bit 디지탈 0번핀
IN2 = micro:bit 디지탈 1번핀
IN3 = micro:bit 디지탈 2번핀
IN4 = micro:bit 디지탈 3번핀
소스
/*
############################################
## sMotor v0.1 Test Program ##
## created by Samuel Matildes ##
############################################
---- sam.naeec@gmail.com -----
This library was made for 4-Phase Stepper Motors
I don't take any resposability for the damage caused to your equipment.
*/
#include "MicroBit.h"
#include "sMotor.h"
//MicroBit uBit;
MicroBitSerial gSerial(USBTX, USBRX);
sMotor motor(P0_0, P0_1, P0_2, P0_3); // creates new stepper motor: IN1, IN2, IN3, IN4
//BusOut motor_out(P0_0, P0_1, P0_2, P0_3); // blue - pink - yellow - orange
int step_speed = 1200; // 1200 ; // set default motor speed
int numstep = 512 ; // defines full turn of 360 degree
//you might want to calibrate this value according to your motor
int step = 0;
int dir = 1; // direction
int main() {
//uBit.init();
//uBit.display.disable();
//Credits
printf("4 Phase Stepper Motor v0.1 - Test Program\r\n");
printf("developed by Samuel Matildes\r\n");
printf("\n\r");
// Screen Menu
printf("Default Speed: %d\n\r",step_speed);
printf("1- 360 degree clockwise step\n\r");
printf("2- 360 degree anticlockwise step\n\r");
printf("3- 180 degree clockwise step\n\r");
printf("4- 180 degree anticlockwise step\n\r");
printf("5- Change Speed\n\r");
while (1) {
if (gSerial.readable()) { // checks for serial
if (gSerial.getc()=='1')
motor.step(numstep,0,step_speed); // number of steps, direction, speed
if (gSerial.getc()=='2')
motor.step(numstep,1,step_speed);
if (gSerial.getc()=='3')
motor.step(numstep/2,0,step_speed);
if (gSerial.getc()=='4')
motor.step(numstep/2,1,step_speed);
if (gSerial.getc()=='5') {
printf("Current Speed: %d\n\r", step_speed);
printf("New speed: \n\r");
//gSerial.scanf("%d",&step_speed); // sets new speed
}
}
}
/*
while(1)
{
switch(step)
{
case 0: motor_out = 0x1; break; // 0001
case 1: motor_out = 0x3; break; // 0011
case 2: motor_out = 0x2; break; // 0010
case 3: motor_out = 0x6; break; // 0110
case 4: motor_out = 0x4; break; // 0100
case 5: motor_out = 0xC; break; // 1100
case 6: motor_out = 0x8; break; // 1000
case 7: motor_out = 0x9; break; // 1001
default: motor_out = 0x0; break; // 0000
}
if(dir) step++; else step--;
if(step>7)step=0;
if(step<0)step=7;
//wait(0.015); // speed
wait_us(step_speed);
}
*/
}
ROC-RK3328-CC 비롯해서 Rockchip 칩을 사용하는 대부분의 SBC 보드들이 안드로이드 OS용 그래픽 가속 드라이버는 제공 되지만, 리눅스용 그래픽 드라이버가 제공 되지 않아 RetroPie와 같은 게임 에뮬레이터를 실행 할 수가 없는데, 최근에 LAKKA용 OS 이미지가 제공 되어 게임 에뮬레이터를 실행 보았습니다. 아쉽게도 PSP 에뮬레이터는 조금 느리게 동작했습니다.
micro:bit를 이용해서 BLE 서버를 만들고 App Inventor를 이용해서 안드로이드 용 BLE 클라이언트를 만들어 보았습니다.
BLE 서버는 BLE 이름과 UUID(고유주소)를 송출하고, 이 정보로 BLE 클라이언트가 접속하면, BLE 기기는 다른 BLE 클라이언트가 접속하지 않도록, BLE 이름을 더 이상 송출하지않고, 서비스목록과 해당 서비스의 특성 정보를 송출합니다. BLE 클라이언트는 필요한 서비스와 특성을 찾아서 용도에 따라 다르겠지만 여기 예제에서는 간단하게 문자열을 주고 받도록 했습니다.
#include "MicroBit.h"
#include "MicroBitUARTService.h"
MicroBit uBit;
MicroBitUARTService *uart;
int connected = 0;
void onConnected(MicroBitEvent e) {
uBit.display.scroll("C");
connected = 1;
// my client will send ASCII strings terminated with the colon character
ManagedString eom(":");
while (connected == 1) {
ManagedString msg = uart->readUntil(eom);
uBit.display.scroll(msg);
}
}
void onDisconnected(MicroBitEvent e) {
uBit.display.scroll("D");
connected = 0;
}
void onButtonA(MicroBitEvent e) {
if (connected == 0) {
uBit.display.scroll("NC");
return;
}
uart->send("YES");
uBit.display.scroll("YES");
}
void onButtonB(MicroBitEvent e) {
if (connected == 0) {
uBit.display.scroll("NC");
return;
}
uart->send("NO");
uBit.display.scroll("NO");
}
void onButtonAB(MicroBitEvent e) {
if (connected == 0) {
uBit.display.scroll("NC");
return;
}
uart->send("GOT IT!!");
uBit.display.scroll("GOT IT!!");
}
int main() {
// Initialise the micro:bit runtime.
uBit.init();
// listen for Bluetooth connection state changes
uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, onConnected);
uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, onDisconnected);
// listen for user button interactions
uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButtonA);
uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonB);
uBit.messageBus.listen(MICROBIT_ID_BUTTON_AB, MICROBIT_BUTTON_EVT_CLICK, onButtonAB);
// Note GATT table size increased from default in MicroBitConfig.h
// #define MICROBIT_SD_GATT_TABLE_SIZE 0x500
uart = new MicroBitUARTService(*uBit.ble, 32, 32);
uBit.display.scroll("AVM");
// If main exits, there may still be other fibers running or registered event handlers etc.
// Simply release this fiber, which will mean we enter the scheduler. Worse case, we then
// sit in the idle task forever, in a power efficient sleep.
release_fiber();
}
App Inventor는 MIT에서 만든 블럭 형태의 코딩으로 안드로이드 어플을 쉽게 만들 수 있어서 IOT 개발시 많이 사용됩니다. 기본적으로 BT 통신만 지원했고, BLE 통신은 지원하지 않았지만, 최근에 확장 라이브러리를 통해서 지원하고 있습니다. BLE 확장 라이브러리를 다운 받아서 Import 하시면 BLE 통신을 구현 할 수 있습니다.
예제는 BLE 목록을 조회하고, 조회된 목록에서 micro:bit를 선택하여 BLE 서버에 접속하고, 미리 정해둔 서비스와 특성을 등록하고, micro:bit에서 A나 B버튼을 선택시 전달 받은 문자열을 텍스트박스에 출력하고, 안드로이드 어플에서도 문자열을 micro:bit에 전송 합니다.
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python3 get-pip.py
WARNING: The directory '/home/bluesanta/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
WARNING: The directory '/home/bluesanta/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
Downloading https://files.pythonhosted.org/packages/62/ca/94d32a6516ed197a491d17d46595ce58a83cbb2fca280414e57cd86b84dc/pip-19.2.1-py2.py3-none-any.whl (1.4MB)
|████████████████████████████████| 1.4MB 150kB/s
Collecting setuptools
Downloading https://files.pythonhosted.org/packages/ec/51/f45cea425fd5cb0b0380f5b0f048ebc1da5b417e48d304838c02d6288a1e/setuptools-41.0.1-py2.py3-none-any.whl (575kB)
|████████████████████████████████| 583kB 379kB/s
Collecting wheel
Downloading https://files.pythonhosted.org/packages/bb/10/44230dd6bf3563b8f227dbf344c908d412ad2ff48066476672f3a72e174e/wheel-0.33.4-py2.py3-none-any.whl
ERROR: launchpadlib 1.10.6 requires testresources, which is not installed.
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-19.2.1 setuptools-41.0.1 wheel-0.33.4
$ rm get-pip.py
pi@raspberrypi:~$ workon cv
(cv) pi@raspberrypi:~$ pip install numpy
(cv) pi@raspberrypi:~$ python
Python 3.6.8 (default, Jan 14 2019, 11:02:34)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> quit()
OpenCV 4를 Python 3 가상 환경에 복사
$ cd ~/.virtualenvs/cv/lib/python3.6/site-packages/
$ ln -s /home/bluesanta/opencv410/opencv-4.1.0/release/lib/python3/cv2.cpython-36m-aarch64-linux-gnu.so cv2.so
$ cd ~
OpenCV 설치 확인
파이썬
$ workon cv
(cv) bluesanta@bluesanta-desktop:~$ python
Python 3.6.8 (default, Jan 14 2019, 11:02:34)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.1.0'
>>> exit()
C++
#include "opencv2/opencv.hpp"
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
cout << "OpenCV version : " << CV_VERSION << endl;
cout << "Major version : " << CV_MAJOR_VERSION << endl;
cout << "Minor version : " << CV_MINOR_VERSION << endl;
cout << "Subminor version : " << CV_SUBMINOR_VERSION << endl;
}
$ g++ opencv_check_version.cpp -o opencv_check_version `pkg-config --cflags --libs opencv4`
$ ./opencv_check_version
OpenCV version : 4.1.0
Major version : 4
Minor version : 1
Subminor version : 0
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python3 get-pip.py
WARNING: The directory '/home/bluesanta/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
WARNING: The directory '/home/bluesanta/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
Downloading https://files.pythonhosted.org/packages/62/ca/94d32a6516ed197a491d17d46595ce58a83cbb2fca280414e57cd86b84dc/pip-19.2.1-py2.py3-none-any.whl (1.4MB)
|████████████████████████████████| 1.4MB 150kB/s
Collecting setuptools
Downloading https://files.pythonhosted.org/packages/ec/51/f45cea425fd5cb0b0380f5b0f048ebc1da5b417e48d304838c02d6288a1e/setuptools-41.0.1-py2.py3-none-any.whl (575kB)
|████████████████████████████████| 583kB 379kB/s
Collecting wheel
Downloading https://files.pythonhosted.org/packages/bb/10/44230dd6bf3563b8f227dbf344c908d412ad2ff48066476672f3a72e174e/wheel-0.33.4-py2.py3-none-any.whl
ERROR: launchpadlib 1.10.6 requires testresources, which is not installed.
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-19.2.1 setuptools-41.0.1 wheel-0.33.4
$ rm get-pip.py