loading
pcDuino v2 has a built-in WiFi module that provides Internet connection. Users are asking how to use the WiFi module in the Arduino style IDE on pcDuino? Is it same as WiFi shield for Arduino?

pcDuino v2 is a single board linux computer itself. The network function is also provided. We don’t need to go through the trouble as we did on Arduino Uno.  In this tutorial, we show a project to remotely control a LED through TCP/IP using Arduino style code.

Step 1: Part List

1 x pcDuino v2 (or 1 x pcDuino v1 and 1 x WiFi USB Dongle)
1 x T board for pcDuino v1 (or T board for pcDuino v2 if pcDuino v2 is used)
1 x 10mm Green LED module
1 x Linker Base Shield
1 x Linker 20cm cable

Step 2: Theory

In this project, on the pcDuino side, we will implement a TCP/IP socket server, which will listen and accept connection from client, when it receives character ’O’, it will turn on the LED, and when it receives ‘F”, it will turn on the LED. No actions if receive something else.

We install a TCP/IP Client on another PC, and use it to send data to the server which is implemented on pcDuino.

Step 3: Sample Code for Arduino IDE

/*
* LED test program
* The LED will be controlled by TCP socket
* This program serves an example of TCP socket server
*
*The TCP socket code is adpoted from : http://www.thegeekstuff.com/2011/12/c-socket-programming/
*
* Please use linker kit LED module,and install it on D2 D3 V G postion
*
* Jingfeng Liu
*
*  5/4/2013
*
*/

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>

#include <core.h>

int led_pin = 2;

int listenfd = 0, connfd = 0;
int n;
struct sockaddr_in serv_addr;

char sendBuff[1025];
  time_t ticks;

void setup()
{

   led_pin = 2;

    pinMode(led_pin, OUTPUT);

   listenfd = socket(AF_INET, SOCK_STREAM, 0);
    memset(&serv_addr, '0', sizeof(serv_addr));
    memset(sendBuff, '0', sizeof(sendBuff));

    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
    serv_addr.sin_port = htons(5000);

    bind(listenfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));

    listen(listenfd, 10);

    connfd = accept(listenfd, (struct sockaddr*)NULL, NULL);

}

void loop()
{

//     ticks = time(NULL);
//    snprintf(sendBuff, sizeof(sendBuff), "Jingfeng Liu%.24s\r\n", ctime(&ticks));
  //     write(connfd, sendBuff, strlen(sendBuff));

       n = read(connfd, sendBuff, strlen(sendBuff) );

     if(n>0)
    {
      if(sendBuff[0]=='O')           digitalWrite(led_pin, HIGH);  // set the LED on
      if(sendBuff[0]=='F')           digitalWrite(led_pin,LOW);  // set the LED off
    }

  //    close(connfd);
  //   sleep(1);

}

Step 4: Result

When we fun the code on pcDuino, on another PC, we open the TCP/IP tool to send data to the server which is implemented on pcDuino. The IP address of pcDuino can be found by typing “$ifconfig” on pcDuino.

A screen shot of TCP client is shown below:
<p>This info is helpful, my goal is to read 10 turn precision pots with 12 bit a/d input for position and transmit to second PCduino controlling heliostat position to stay focused on a spot throughout the day.</p>
<p>I wish you had commented the function of each #include module as I'm not a c programmer, my forte is assembler and forth.</p>

About This Instructable

8,372views

26favorites

License:

More by Yanny Guo:Use pcDuino as Photo Booth Controller Use Si4703 FM Breakout Board on Arduino Uno Use SIM900 GPRS/GSM Shield on pcDuino 
Add instructable to: