39c ConnectOne Demo

ConnectOne + Arduino Live Demo


Line 1:
Red LED:
Line 2: Blue LED:

This is a live demonstration of internal web server running on ConnectOne's WiFi module (WiReach MAX-SMT). The web server enables remote control over various peripherals. The video stream is generated by a webcam located above the demo.

Here is the Arduino source code, used in this demo:
#include <string.h>
#include <stdlib.h>
#include <SPI.h>

#define txPin 2

int SPI_CS 		= 10;
int DATA_RDY		= 3;
int SPI_Int 		= 2;

int ledBluePin 		= 5; // PWM enabled pin
int ledBlueGndPin 	= 4;

int ledRedPin 		= 6; // PWM enabled pin
int ledRedGndPin 	= 7;

char SPI_read_buffer [100];
char *SPI_read_ptr;
char str[20];

int SPI_buffer_ready = 0;
int SPIbytesToRead = 0;


void setup()
{
	pinMode(txPin, OUTPUT);
	Serial.begin(9600);
	Serial.write("Starting");
	delay(500);	Serial.write("1");
	delay(500);	Serial.write("2");
	delay(500);	Serial.write("3");
	delay(500);
	
	SPI_cs_high();
	pinMode(SPI_CS,		OUTPUT);
	pinMode(DATA_RDY,	INPUT);
	pinMode(SPI_Int,	INPUT);
	
	pinMode(ledBluePin, 	OUTPUT);
	pinMode(ledBlueGndPin, 	OUTPUT);
	pinMode(ledRedPin, 	OUTPUT);
	pinMode(ledRedGndPin, 	OUTPUT);
	
	digitalWrite(ledBlueGndPin,	LOW);
	digitalWrite(ledRedGndPin,	LOW);
	
	SPI.begin();
	SPI.setDataMode(SPI_MODE1);
	SPI.setBitOrder(MSBFIRST);
	SPI.setClockDivider(SPI_CLOCK_DIV2);
	
	while (digitalRead(SPI_Int)) 
		SPI_readln(); // Read out any remaining responses

	clearLCD();

	SPI_write("AT+IIPA?\r\n");	// Check for IP address
	Serial.write(SPI_readln());	// Show it on LCD
	SPI_readln(); 			// Read out I/OK

	delay(3000);
	selectLineTwo();			
	SPI_write("at+iup=1\r\n");	// Register on ConnectOne DCS server
	Serial.write(SPI_readln());
	Serial.write(SPI_readln());

}



void loop()
{
  int LCDbrightness, RLEDperiod, BLEDperiod;
	
  while(1) 
  {
    if (digitalRead(DATA_RDY)) 	// Parameters updated on the web-site
    {
      SPI_write("at+ilcdtext1?\r\n"); // get lcdtext1 value from WiReach MAX
      clearLCD();
      selectLineOne();
      Serial.write(SPI_readln()); // Send lcdtext1 field text to LCD row 1
      SPI_readln();			// Read out I/OK
      selectLineTwo();
      SPI_write("at+ilcdtext2?\r\n"); // get lcdtext2 value from WiReach MAX
      Serial.write(SPI_readln()); // Send lcdtext2 field text to LCD row 2
      SPI_readln();			// Read out I/OK
  
      SPI_write("AT+IRLEDperiod?\r\n"); // get RLEDperiod from WiReach MAX
      RLEDperiod = atoi(SPI_readln()); // Convert  to int
      analogWrite(ledRedPin, RLEDperiod);
      SPI_readln();			// Read out I/OK

      SPI_write("AT+IBLEDperiod?\r\n"); // get BLEDperiod from WiReach MAX
      BLEDperiod = atoi(SPI_readln()); // Convert to int
      analogWrite(ledBluePin, BLEDperiod); 
      SPI_readln();			// Read out I/OK
    }  
  }
}

inline void SPI_cs_low()
{
	digitalWrite(SPI_CS,LOW);
}

inline void SPI_cs_high()
{
	digitalWrite(SPI_CS,HIGH);
}

void SPI_write_char(char value)
{
	int timer=100;
  	while (digitalRead(SPI_Int)) {  // iChip want us to WAIT
		
		delayMicroseconds(100);
		if ( timer-- == 0)
		{
			return;
		}
	}
	SPI_cs_low();
	SPI.transfer(value);
	SPI_cs_high();
	//Serial.write(value);
}

void SPI_write(char *str)
{
	while (*str) SPI_write_char(*str++);
}

inline char SPI_read_char()
{
  SPI_cs_low();
  char tmp = SPI.transfer(0);
  SPI_cs_high();
  return tmp;
}

char * SPI_readln()
{
	char ch;
	int EOL=0;
	
	SPI_read_ptr = &SPI_read_buffer[0];

	while (!EOL)
	{
		
		while (!digitalRead(SPI_Int)) {}; // wait for SPI_int

		if (SPIbytesToRead == 0)
		{
			SPI_cs_low();
			int bytesToReadh = (SPI.transfer(0x00) & 0xf) << 8;
			int bytesToReadl = SPI.transfer(0x00);
			SPIbytesToRead = bytesToReadh | bytesToReadl;
			SPI_cs_high();
		}
			
		if (SPIbytesToRead > 100)
		{
			strcpy (SPI_read_buffer,"-ERROR-\r\n\0");
			SPI_read_ptr = &SPI_read_buffer[9];
		}
		else
		{	
			while (SPIbytesToRead)
			{
				ch = SPI_read_char();

				switch (ch) 
				{
					case 0xD: // CR
						*(SPI_read_ptr) = 0;
						break;
					case 0xA: // LF
						EOL = 1;
						SPIbytesToRead--;
						goto exit;
						break;
					default: 
						*(SPI_read_ptr++) = ch;
				}
				SPIbytesToRead--;
			}
		}
		while (digitalRead(SPI_Int)) {}; // Wait for SPI_int to fall
	}
	exit:

	return SPI_read_buffer;
}
void selectLineOne(){  //puts the cursor at line 0 char 0.
	Serial.write(0xFE);   //command flag
	Serial.write(128);    //position
}
void selectLineTwo(){  //puts the cursor at line 0 char 0.
	Serial.write(0xFE);   //command flag
	Serial.write(192);    //position
}
void clearLCD(){
	Serial.write(0xFE);   //command flag
	Serial.write(0x01);   //clear command.
}
0