정보나눔

오픈소스하드웨어 프로젝트에 대한 다양한 정보를 나누는 공간입니다.

OrangeBoard WiFi와 조이스틱 센서 쉴드로 RC카 제어해보기
하늘 | 2017-11-30

계속 아두이노 "OrangeBoard WiFi와 조이스틱 센서 쉴드로 RC카 제어해보기"에서 막히네요.  죄송한데 좀 도와 주세요.

 

소스 코드(rc car):

#include <SPI.h>
#include <WizFi250.h>
#include <WizFi250Udp.h>


char ssid[] = "DIR-815_Wiznet";            // your network SSID (name)
char pass[] = "12345678";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

unsigned int localPort = 10002;  // local port to listen on

char packetBuffer[255];          // buffer to hold incoming packet
char ReplyBuffer[] = "ACK";      // a string to send back

WiFiUDP Udp;

void printWifiStatus();

//RCcar motor Pin
const int motorLeftF = 7;
const int motorLeftB = 6;
const int motorRightF = 8;
const int motorRightB = 9;

void setup() {
  // initialize serial for debugging
  Serial.begin(115200);

  WiFi.init();

  // 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.beginAP(ssid, 10, pass, ENC_TYPE_WPA2_PSK);
  }

  Serial.println("Connected to wifi");
  printWifiStatus();

  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  Udp.begin(localPort);

  Serial.print("Listening on port ");
  Serial.println(localPort);

  pinMode(motorRightF, OUTPUT);
  pinMode(motorRightB, OUTPUT);
  pinMode(motorLeftF, OUTPUT);
  pinMode(motorLeftB, OUTPUT);
}

void loop() {

  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize)
  {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remoteIp = Udp.remoteIP();
    Serial.print(remoteIp);
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    int len = Udp.read(packetBuffer, 200);
    if ( len > 0 ) {
      packetBuffer[len] = 0;

    }
    Serial.println("Contents:");
    Serial.println(packetBuffer);
    if(packetBuffer[0] == 'F') {
      digitalWrite(6,HIGH);
      digitalWrite(9,HIGH);
      digitalWrite(7,LOW);
      digitalWrite(8,LOW);
    }
    else if(packetBuffer[0] == 'B') {
      digitalWrite(7,HIGH);
      digitalWrite(8,HIGH);
      digitalWrite(6,LOW);
      digitalWrite(9,LOW);
    }
    else if(packetBuffer[0] == 'N') {
      digitalWrite(7,LOW);
      digitalWrite(8,LOW);
      digitalWrite(6,LOW);
      digitalWrite(9,LOW);
    }
    else if(packetBuffer[0] == 'R') {
      digitalWrite(7,LOW);
      digitalWrite(8,HIGH);
      digitalWrite(6,HIGH);
      digitalWrite(9,LOW);
    }
    else if(packetBuffer[0] == 'L') {
      digitalWrite(7,HIGH);
      digitalWrite(8,LOW);
      digitalWrite(6,LOW);
      digitalWrite(9,HIGH);
    }

    // send a reply, to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
  }
}


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

 

소스 코드(조종기):

#include <SPI.h>
#include "WizFi250.h"
#include "WizFi250Udp.h"

char ssid[] = "DIR-815_Wiznet";  // your network SSID (name)
char pass[] = "12345678";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

char timeServer[] = "192.168.12.101";  // NTP server
unsigned int localPort = 2390;        // local port to listen for UDP packets

const int NTP_PACKET_SIZE = 48;  // NTP timestamp is in the first 48 bytes of the message

char packetBuffer[NTP_PACKET_SIZE]; // buffer to hold incoming and outgoing packets

// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;

unsigned long sendNTPpacket(char *ntpSrv);

void setup()
{
  // initialize serial for debugging
  Serial.begin(115200);

  WiFi.init();

  // 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);
  }

  pinMode(A2, INPUT);
  pinMode(A3, INPUT);
  pinMode(8, INPUT);
  pinMode(9, INPUT);

  // you're connected now, so print out the data
  Serial.println("You're connected to the network");

  Udp.begin(localPort);
}

void loop()
{
  sendNTPpacket(timeServer); // send an NTP packet to a time server
  // wait to see if a reply is available
  delay(50);

  Serial.println(Udp.parsePacket());
  // wait ten seconds before asking for the time again
  delay(1);
}

unsigned long sendNTPpacket(char *ntpSrv)
{
  int joystickH = analogRead(A0);
  int joystickV = analogRead(A1);
  memset(packetBuffer, 0, NTP_PACKET_SIZE);
  if (joystickH > 800) {
    Serial.println("Right");
    packetBuffer[0] = 'R';
  }
  else if (joystickH < 300) {
    Serial.println("Left");
    packetBuffer[0] = 'L';
  }
  else if (joystickV > 800) {
    Serial.println("Forward");
    packetBuffer[0] = 'F';
  }
  else if (joystickV < 300) {
    Serial.println("Backward");
    packetBuffer[0] = 'B';
  }
  else {
    Serial.println("Natural");
    packetBuffer[0] = 'N';
  }
  Udp.beginPacket(ntpSrv, 10002); //NTP requests are to port 123
  Udp.write(packetBuffer, NTP_PACKET_SIZE);
  Udp.endPacket();
}

 

그런데 어찌나 오류가 많이 뜨는지.......

일단 rc car 오류:

sketch_nov30e:8: error: 'WL_IDLE_STATUS' was not declared in this scope

sketch_nov30e:15: error: 'WiFiUDP' does not name a type

sketch_nov30e.ino: In function 'void setup()':

sketch_nov30e:29: error: 'WiFi' was not declared in this scope

sketch_nov30e:32: error: 'WL_NO_SHIELD' was not declared in this scope

sketch_nov30e:39: error: 'WL_CONNECTED' was not declared in this scope

sketch_nov30e:43: error: 'ENC_TYPE_WPA2_PSK' was not declared in this scope

sketch_nov30e:51: error: 'Udp' was not declared in this scope

 

As of Arduino 1.0, the Udp class in the Ethernet library has been renamed to EthernetUdp.

 

sketch_nov30e.ino: In function 'void loop()':

sketch_nov30e:65: error: 'Udp' was not declared in this scope

 

As of Arduino 1.0, the Udp class in the Ethernet library has been renamed to EthernetUdp.

 

sketch_nov30e:71: error: 'IPAddress' was not declared in this scope

sketch_nov30e:71: error: expected `;' before 'remoteIp'

sketch_nov30e:72: error: 'remoteIp' was not declared in this scope

sketch_nov30e.ino: In function 'void printWifiStatus()':

sketch_nov30e:125: error: 'WiFi' was not declared in this scope

sketch_nov30e:128: error: 'IPAddress' was not declared in this scope

sketch_nov30e:128: error: expected `;' before 'ip'

sketch_nov30e:130: error: 'ip' was not declared in this scope

그 다음은 조종기 오류:

sketch_nov30f:7: error: 'WL_IDLE_STATUS' was not declared in this scope

sketch_nov30f:17: error: 'WiFiUDP' does not name a type

sketch_nov30f.ino: In function 'void setup()':

sketch_nov30f:26: error: 'WiFi' was not declared in this scope

sketch_nov30f:29: error: 'WL_NO_SHIELD' was not declared in this scope

sketch_nov30f:36: error: 'WL_CONNECTED' was not declared in this scope

sketch_nov30f:51: error: 'Udp' was not declared in this scope

 

As of Arduino 1.0, the Udp class in the Ethernet library has been renamed to EthernetUdp.

 

sketch_nov30f.ino: In function 'void loop()':

sketch_nov30f:60: error: 'Udp' was not declared in this scope

 

As of Arduino 1.0, the Udp class in the Ethernet library has been renamed to EthernetUdp.

 

sketch_nov30f.ino: In function 'long unsigned int sendNTPpacket(char*)':

sketch_nov30f:90: error: 'Udp' was not declared in this scope

 

As of Arduino 1.0, the Udp class in the Ethernet library has been renamed to EthernetUdp.

 

좀 이상해요. 분명히 해더파일이 있는데.....

 

 

 

좀 도와 주세요.

 

 

이전글   |    if - else if 구문 문의드립니다. 2017-11-30
다음글   |    rtc모둘 ds1302 질문드립니다. 2017-11-30