Pages: [1]   Go Down
Author Topic: Sending instrument data from Arduino to MatLab - WiShield  (Read 3243 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I'm new of the community even if I've been reading the forum for quite a long time.

I'm trying to built a system that should pick-up measures  from a laser range finder -720 measures at 10Hz, so 7200 measures every sec.-, this is connected to the Arduino through a USB shield and a program that picks up the measures and writes them in a long array. (One array every set of measures, so 10 array each second).
Than this data should be sent to the PC (MatLab) using a WiFi connection (WiShield). Right now I managed to set up a socket (using the code provided on the AsyncLabs) and I can send string of number to MatLab.
But I have severe limitations in sending this big array (even because I have to send value bigger than 256 so more than one byte).

Do You know a way I could work out to send this data?

I'm sorry if my questions are "stupid" or quite similar to others in the forum, but I tried to search some info in the forum and I couldn't find. Also my knowledge about communication/protocol is around 0 so it's hard to me to direct the search in the correct direction... (I'm a mechanical eng. not a computer eng! :-( )

Best regards
Edoardo
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13702
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
so 7200 measures every sec.
That is quite a lot for an arduino, what sensor are you using? what is the datatype of one measurement? (long, int, byte, float)

what is the duration (continuous,  5 seconds?)

Quote
Do You know a way I could work out to send this data?
yep, but I don't know if wifi is the right way, as it might not have the throughput to send those 7200 measurements. IIRC my ethernetshield reaches approx 5KB /second so that would imply ~5000 bytes, or ~1000 longs per second.

An option might be to use a simple compression scheme and only send the delta's but if that is possible depends very much of the type of data one gets.
e.g. the values 1000 1002 1004 999 1000 1000 1020 1024 1014 1000 993 1000 1002can be send
as 1000,+2, +4, -1, +0, +0, +20, +24, +14, 0, 993, +7 +9   // delta wrt an initial value, resending a reference value every 10 measurements.
or 1000, +2, +2 -5, +1, +0, +20, +4, -10, -14, 993, +7, +2 // delta wrt previous value, resending ref every n values.

The second has better dynamic properties as you can go +-127 (1 byte) from the last measurement while the first goes +-127 from the reference measurement. If there is a steep rise the first coding will "overflow" faster than the second one. The drawback of teh second is that missing one value corrupts the rest of one "burst".

Can you tell more about the details of the proj. post links of datasheet of the sensor?

Quote
I'm sorry if my questions are "stupid"
2 answers on this one:
- "he who asks questions is stupid for a moment, he who not asks them is stupid forever" - chinese proverb
- questions are never stupid, answers can be (some writer I do not recall)


Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Right now I'm using an Hokuyo Scanning Range Finder (http://www.hokuyo-aut.jp/02sensor/07scanner/urg_04lx_ug01.html).

This will be connected to an Arduino that will format the data in arrays with 720 measures, each measure can have a value from 0 to 5600.
Since we are measuring a room/indoor environment, tha "jump" in in tha value may be big (think at measuring a close wall and the seeing an open door... the jump can send the value from 500 to 5600 ), but the compressing may be an idea. If I have understand in a good way the TCPIP protocol, this should "verify" that package it sents, while UDP doesn't, so I should be able using a TCPIP protocol to check if I send the entire set. So the second compressing scheme should be better. Is it right?

Here is the datasheet: http://www.hokuyo-aut.jp/02sensor/07scanner/download/data/URG-04LX_spec.pdf
Thanks for the help


 
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I made some very easy test trying to send some string from the Arduino to MatLab, I can do it but it's SUPER SLOW....  takes 0.4 sec to send 500Bytes (I mean Bytes not KBytes...).
Even with a compression scheme I won't need less than 800Bytes each 0.1 second... I can slow down the sampling rate... but less than 2-4Hz wouldn't be good for the purpose of the research... (mapping a room)
Did anyone of you ever tried tested this WiFi shield?? Am I doing something wrong to have the connection so slow??
Thanks
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13702
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Can you post your arduino code so I can have a look if I see optimizations?

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Right now I'm just using the code provided with the WiShield
Code:
/******************************************************************************

  Filename: socketapp.c
  Description: Simple socket programming example for the WiShield 1.0

 ******************************************************************************

  TCP/IP stack and driver for the WiShield 1.0 wireless devices

  Copyright(c) 2009 Async Labs Inc. All rights reserved.

  This program is free software; you can redistribute it and/or modify it
  under the terms of version 2 of the GNU General Public License as
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  more details.

  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc., 59
  Temple Place - Suite 330, Boston, MA  02111-1307, USA.

  Contact Information:
  <asynclabs@asynclabs.com>

   Author               Date        Comment
  ---------------------------------------------------------------
   AsyncLabs 06/06/2009 Initial version

 *****************************************************************************/

/*
 * This is a short example of how to write uIP applications using
 * protosockets.
 */

/*
 * We define the application state (struct socket_app_state) in the
 * socketapp.h file, so we need to include it here. We also include
 * uip.h (since this cannot be included in socketapp.h) and
 * <string.h>, since we use the memcpy() function in the code.
 */
#include "socketapp.h"
#include "uip.h"
#include <string.h>

/*
 * Declaration of the protosocket function that handles the connection
 * (defined at the end of the code).
 */
static int handle_connection(struct socket_app_state *s);
/*---------------------------------------------------------------------------*/
/*
 * The initialization function. We must explicitly call this function
 * from the system initialization code, some time after uip_init() is
 * called.
 */
void socket_app_init(void)
{
  /* We start to listen for connections on TCP port 1000. */
  uip_listen(HTONS(1000));
}
/*---------------------------------------------------------------------------*/
/*
 * In socketapp.h we have defined the UIP_APPCALL macro to
 * socket_app_appcall so that this function is uIP's application
 * function. This function is called whenever an uIP event occurs
 * (e.g. when a new connection is established, new data arrives, sent
 * data is acknowledged, data needs to be retransmitted, etc.).
 */
void socket_app_appcall(void)
{
  /*
   * The uip_conn structure has a field called "appstate" that holds
   * the application state of the connection. We make a pointer to
   * this to access it easier.
   */
  struct socket_app_state *s = &(uip_conn->appstate);

  /*
   * If a new connection was just established, we should initialize
   * the protosocket in our applications' state structure.
   */
  if(uip_connected()) {
    PSOCK_INIT(&s->p, s->inputbuffer, sizeof(s->inputbuffer));
  }

  /*
   * Finally, we run the protosocket function that actually handles
   * the communication. We pass it a pointer to the application state
   * of the current connection.
   */
  handle_connection(s);
}
/*---------------------------------------------------------------------------*/
/*
 * This is the protosocket function that handles the communication. A
 * protosocket function must always return an int, but must never
 * explicitly return - all return statements are hidden in the PSOCK
 * macros.
 */
static int handle_connection(struct socket_app_state *s)
{
  PSOCK_BEGIN(&s->p);

  PSOCK_SEND_STR(&s->p, "Hello. What is you name?\n");
  PSOCK_READTO(&s->p, '\n');
  PSOCK_SEND_STR(&s->p, "Hello ");
  PSOCK_SEND_STR(&s->p, s->inputbuffer);
  memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
  PSOCK_CLOSE(&s->p);

  PSOCK_END(&s->p);
}
/*---------------------------------------------------------------------------*/

Code:
/*
 * Socket App
 *
 * A simple socket application example using the WiShield 1.0
 */

#include <WiShield.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,2}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"RobotConnection"}; // max 32 bytes

unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_ADHOC;

unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------

void setup()
{
WiFi.init();
}

void loop()
{
WiFi.run();
}

This is the code from the UDPSocket example from WiShield Asynclabs, unfortunately the code for the TCPIP protocol is nested in several different files. smiley-sad
I don-t know if anyone of you have any experience with this wi-fi shield on Arduino.
Logged

Pages: [1]   Go Up
Jump to: