USKYLENS는 USB로 시리얼 통신용 CP2101 (USB to UART Bridge) 칩을 사용하고 있어 CP2101 용 드라이버를 설치해야 합니다. ZIP파일 압축을 풀고 해당 윈도우 버전의 driver 폴더에서 설치 프로그램을 실행합니다. Windows10 용 64 비트 설치 (CP210xVCPInstaller_x64.exe)입니다.
업그레이드 실시
HUSKYLENS를 USB 케이블로 PC와 연결하고 펌웨어 업데이트용 소프트웨어 (K-Flash.exe)를 실행합니다
Device 선택
K-Flash.exe를 실행하면 HUSKYLENS에 탑재 된 CP2101과 자동으로 연결됩니다.. CP2101과 연결이 올바르게 인식하면 Device 란의 콤보박스에 "Silicon Labs CP210x USB to UART Bridge"을 찾아서 선택합니다. 콤보박스 목록에 "Silicon Labs CP210x USB to UART Bridge"가 없으면 HUSKYLENS와 USB연결을 확인하시기 바랍니다.
펌웨어 파일 선택
Firmware 란의 오른쪽에있는 [...]버튼을 클릭하여 펌웨어 (HUSKYLENSWithModelVx.x.xStable.kfpkg)을 선택합니다. 선택 후 Firmware 란에 파일 이름이 표시되어 있는지 확인합니다.
펌웨어 업데이트 실행
'Open terminal after flash "의 체크를 해제합니다. "Flash"를 클릭하여 펌웨어 쓰기 시작합니다.
펌웨어 업데이트 진행
펌웨어 쓰기가 완료 될 때까지 기다립니다. 업데이트는 약 5분의 시간이 걸립니다. 저장 중 HUSKYLENS의 디스플레이는 꺼지고, 업데이트가 완료될때까지 HUSKYLENS와 USB 연결을 분리하시면 안됩니다.
펌웨어 업데이트 완료
펌웨어 업데이트가 완료되면 아래와 같이 완료 메시지가 표시되고 HUSKYLENS가 다시 시작합니다. "OK"를 클릭 한 후 K-Flash.exe를 종료합니다.
펌웨어 업데이트 확인
펌웨어 업그레이드된 HUSKYLENS에서 펌웨어 버전을 확인하려면 "General Settings"를 선택한 후, 메뉴를 오른쪽으로 이동합니다. "Version x.x.xStable '처럼 버전이 표시되므로 업데이트된 펌웨어 버전과 일치하는지 확인 하실수 있습니다.
/*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);
}
/*
WiFiEsp example: ConnectWPA
This example connects to an encrypted WiFi network using an ESP8266 module.
Then it prints the MAC address of the WiFi shield, the IP address obtained
and other network details.
For more details see: http://yaab-arduino.blogspot.com/p/wifiesp-example-connect.html
*/
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
char ssid[] = "Twim"; // your network SSID (name)
char pass[] = "12345678"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
void setup()
{
// initialize serial for debugging
Serial.begin(115200);
// initialize serial for ESP module
Serial1.begin(115200);
// initialize ESP module
WiFi.init(&Serial1);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
Serial.println("You're connected to the network");
}
void loop()
{
// print the network connection information every 10 seconds
Serial.println();
printCurrentNet();
printWifiData();
delay(10000);
}
void printWifiData()
{
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print your MAC address
byte mac[6];
WiFi.macAddress(mac);
char buf[20];
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
Serial.print("MAC address: ");
Serial.println(buf);
}
void printCurrentNet()
{
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print the MAC address of the router you're attached to
byte bssid[6];
WiFi.BSSID(bssid);
char buf[20];
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", bssid[5], bssid[4], bssid[3], bssid[2], bssid[1], bssid[0]);
Serial.print("BSSID: ");
Serial.println(buf);
// print the received signal strength
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI): ");
Serial.println(rssi);
}
/* IRremote:
IRrecvDemo - demonstrates receiving IR codes with IRrecv
An IR detector/demodulator must be connected to the input RECV_PIN.
Version 0.1 July, 2009
Copyright 2009 Ken Shirriff * http://arcfn.com
*/
#include <IRremote.h>
int RECV_PIN = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
}
적외선 센서 연동 RC CAR 배선
적외선 센서 연동 RC CAR 소스
#include <IRremote.h>
#include <Ultrasonic.h>
#include <SoftwareSerial.h>
int IR_RECV_PIN = 12;
int rc_car_mode = 2;
IRrecv irrecv(IR_RECV_PIN);
SoftwareSerial btSerial(9, 8); //Connect HC-06. Use your (TX, RX) settings
Ultrasonic ultrasonic(10,11); // (Trig PIN,Echo PIN)
//모터A 컨트롤
int enA = 6;
int IN1 = 7;
int IN2 = 5;
//모터B 컨트롤
int enB = 3;
int IN3 = 4;
int IN4 = 2;
decode_results ir_results;
String receiveStr=""; //받는 문자열
String olfReceiveStr=""; //받는 문자열
#define MOTER_SPEED 255 // MAX 255
void setup()
{
irrecv.enableIRIn(); // Start the receiver
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
Serial.begin(9600);
Serial.println("Hello!");
btSerial.begin(9600); // set the data rate for the BT port
}
void loop()
{
analogWrite(enA, MOTER_SPEED);
analogWrite(enB, MOTER_SPEED);
int value = ultrasonic.Ranging(CM);
Serial.print(value); // CM or INC
Serial.print(" cm / " );
boolean is_forward = true;
if (value <= 15) {
is_forward = false;
}
if (rc_car_mode > 2) {
rc_car_mode = 1;
}
switch (rc_car_mode) {
case 1:
loop_bluetooth(is_forward);
break;
case 2:
loop_irrecv(is_forward);
break;
}
Serial.print("\n");
}
void loop_irrecv(boolean is_forward) {
receiveStr = "";
if (irrecv.decode(&ir_results)) {
Serial.print(ir_results.value, HEX);
switch(ir_results.value)
{
case 0xFF629D:
Serial.print(" / ch"); // ch
receiveStr = "C";
break;
case 0xFF18E7:
Serial.print(" / Forward"); // Button 2
receiveStr = "F";
break;
case 0xFF10EF:
Serial.print(" / Left"); // Button 4
receiveStr = "L";
break;
case 0xFF38C7:
Serial.print(" / Stop"); // Button 5
receiveStr = "S";
break;
case 0xFF5AA5:
Serial.print(" / Right"); // Button 6
receiveStr = "R";
break;
case 0xFF4AB5:
Serial.print(" / Back"); // Button 8
receiveStr = "B";
break;
}
irrecv.resume(); // Receive the next value
loop_moter_command(is_forward, receiveStr);
}
}
void loop_bluetooth(boolean is_forward) {
// put your main code here, to run repeatedly:
receiveStr="";
while(btSerial.available()) //mySerial에 전송된 값이 있으면
{
char myChar = (char)btSerial.read(); //mySerial int 값을 char 형식으로 변환
receiveStr+=myChar; //수신되는 문자를 receiveStr에 모두 붙임 (1바이트씩 전송되는 것을 연결)
delay(5); //수신 문자열 끊김 방지
}
loop_moter_command(is_forward, receiveStr);
}
void loop_moter_command(boolean is_forward, String receiveStr) {
if (receiveStr.length() > 0) {
Serial.print(receiveStr);
if (receiveStr == "C") {
rc_car_mode++;
} else if (receiveStr == "F") {
if (is_forward) {
bothMotorStart(); // 전진
} else {
stopAllMotor();
}
} else if (receiveStr == "S") {
stopAllMotor();
} else if (receiveStr == "R") {
turnRight(); // 오른쪽으로 턴
} else if (receiveStr == "L") {
turnLeft(); // 왼쪽으로 턴
} else if (receiveStr == "B") {
bothMotorBack(); // 후진
}
olfReceiveStr = receiveStr;
} else if (!is_forward && olfReceiveStr == "F") {
stopAllMotor();
}
}
//모터A,B 정회전
void bothMotorStart()
{
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
}
//모터A,B 역회전
void bothMotorBack()
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
}
//모터A,B Stop
void stopAllMotor()
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
}
//모터A 역회전, 모터B 정회전
void turnLeft()
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
}
//모터A 정회전, 모터B 역회전
void turnRight()
{
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
}
//모터A 정회전, 모터B Stop
void motorA_Rotation()
{
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
}
//모터A Stop, 모터B 정회전
void motorB_Rotation()
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
}
//모터A 역회전, 모터B Stop
void motorA_Reverse()
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
}
//모터A Stop, 모터B 역회전
void motorB_Reverse()
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
}
#include <Ultrasonic.h>
Ultrasonic ultrasonic(10,11); // (Trig PIN,Echo PIN)
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print(ultrasonic.Ranging(CM)); // CM or INC
Serial.println(" cm" );
delay(100);
}
HC-SR04 센서 연동 RC CAR 배선
HC-SR04 센서 연동 RC CAR 소스
#include <Ultrasonic.h>
#include <SoftwareSerial.h>
SoftwareSerial btSerial(9, 8); //Connect HC-06. Use your (TX, RX) settings
Ultrasonic ultrasonic(10,11); // (Trig PIN,Echo PIN)
//모터A 컨트롤
int enA = 6;
int IN1 = 7;
int IN2 = 5;
//모터B 컨트롤
int enB = 3;
int IN3 = 4;
int IN4 = 2;
String receiveStr=""; //받는 문자열
String olfReceiveStr=""; //받는 문자열
#define MOTER_SPEED 255 // MAX 255
void setup()
{
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
pinMode(IN3,OUTPUT);
pinMode(IN4,OUTPUT);
Serial.begin(9600);
Serial.println("Hello!");
btSerial.begin(9600); // set the data rate for the BT port
}
void loop()
{
analogWrite(enA, MOTER_SPEED);
analogWrite(enB, MOTER_SPEED);
int value = ultrasonic.Ranging(CM);
Serial.print(value); // CM or INC
Serial.print(" cm / " );
if (value <= 15) {
//stopAllMotor();
loop_bluetooth(false);
} else {
loop_bluetooth(true);
//loop_line_tracer();
}
Serial.print("\n");
}
void loop_bluetooth(boolean is_forward) {
// put your main code here, to run repeatedly:
receiveStr="";
while(btSerial.available()) //mySerial에 전송된 값이 있으면
{
char myChar = (char)btSerial.read(); //mySerial int 값을 char 형식으로 변환
receiveStr+=myChar; //수신되는 문자를 receiveStr에 모두 붙임 (1바이트씩 전송되는 것을 연결)
delay(5); //수신 문자열 끊김 방지
}
if (receiveStr.length() > 0) {
Serial.print(receiveStr);
if (receiveStr == "F") {
if (is_forward) {
bothMotorStart(); // 전진
} else {
stopAllMotor();
}
} else if (receiveStr == "S") {
stopAllMotor();
} else if (receiveStr == "R") {
turnRight(); // 오른쪽으로 턴
} else if (receiveStr == "L") {
turnLeft(); // 왼쪽으로 턴
} else if (receiveStr == "B") {
bothMotorBack(); // 후진
}
olfReceiveStr = receiveStr;
} else if (!is_forward && olfReceiveStr == "F") {
stopAllMotor();
}
}
//모터A,B 정회전
void bothMotorStart()
{
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
}
//모터A,B 역회전
void bothMotorBack()
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
}
//모터A,B Stop
void stopAllMotor()
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
}
//모터A 역회전, 모터B 정회전
void turnLeft()
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
}
//모터A 정회전, 모터B 역회전
void turnRight()
{
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
}
//모터A 정회전, 모터B Stop
void motorA_Rotation()
{
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
}
//모터A Stop, 모터B 정회전
void motorB_Rotation()
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
}
//모터A 역회전, 모터B Stop
void motorA_Reverse()
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
}
//모터A Stop, 모터B 역회전
void motorB_Reverse()
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
}