My Cart

Cooking Hacks Trip: Measuring acceleration with Waspmote in Port AventuraSeptember 25, 2012

[Artículo Prensa (En Español)]
[En Español]

Last June, we prepared a trip to pass a nice day with Cooking Hacks Team!! Destination: Port Aventura, one of the biggest theme parks in Europe, where one of the most impressive roller coasters of the world was inaugurated: Shambhala.

As we are a bit "geeks", someone suggested to use Waspmote to measure the acceleration of the roller coasters in Port Aventura so we said: "Why NOT?" We put Waspmote into an enclosure and programmed it with a simple code to measure the data from the 3-axis accelerometer which is included in the board, and save them in the microSD card. We connected the Wifi module and the code sent the data to our Smartphone each 2 minutes. The tests during the week were successful but... we had to test it in a real environment!!

/*
 * PORT AVENTURA CODE
 */

// global variables
char data[100];
char* filename="log.txt";
int value=0;
long time=0;

void setup()
{
  // accelerometer setup
  ACC.ON();

  // USB port setup
  USB.begin();
  USB.println("start");

  // EEPROM register setup
  //Utils.writeEEPROM(300,0);
  value=Utils.readEEPROM(300);
  USB.println(value);

  // Writing in the EEPROM
  Utils.writeEEPROM(300,value+1);

  // RTC on
  RTC.ON();

  // SD ON
  SD.ON();

  // create file
  if(SD.create(filename)) USB.println("file created");
  else USB.println("file NOT created");

  // new rollercoaster log:
  if(SD.appendln(filename,"\n\n\n--------------------------")) USB.println("append ok");
  else USB.println("append failed");
  sprintf(data, "%d - This is a new rollercoaster. Time:%s",value,RTC.getTime());
  // append data to files
  if(SD.appendln(filename,data)) USB.println("append ok");
  else USB.println("append failed");
  if(SD.appendln(filename,"--------------------------\n")) USB.println("append ok");
  else USB.println("append failed");

  // set green led on when measurement starts
  Utils.setLED(LED1,LED_ON);

  // get actual time
  time=millis();

}

void loop()
{
  // create new frame to be written
  sprintf(data, "millis:%lu#x:%d#y:%d#z:%d#",millis(),ACC.getX(),ACC.getY(),ACC.getZ());

  // append data to file
  if(SD.appendln(filename,data))
  {
    Utils.setLED(LED1,LED_ON);
  }
  else
  {
    Utils.setLED(LED1,LED_OFF);
  }

  // After 2 minutes of measurement, send WIFI data
  if(millis()-time > 120000)
  {
    sendWIFI();
    time=0;
  }

}

void sendWIFI()
{
  // First, initialize the WIFI API and the connections with the waspmote
  WIFI.begin();
  // Then switch on the WIFI module on the desired socket.
  WIFI.ON(socket0);
  // If we don't know what configuration had the module, reset it.
  WIFI.resetValues();

  // 1. Configure the transport protocol (UDP, TCP, FTP, HTTP...)
  WIFI.setConnectionOptions(UDP);
  // 2. Configure the way the modules will resolve the IP address.
  WIFI.setDHCPoptions(AUTO_IP);
  // 3. Configure how to connect the AP.
  WIFI.setAutojoinAuth(ADHOC);
  // 3.1 Sets the name of the ADhoc network.
  WIFI.setESSID("libelium_ADHOC");
  // 3.2 Sets the channel of the ADhoc network
  WIFI.setChannel(6);

  // 3. call function to create/join the Adhoc network.
  if(WIFI.setJoinMode(CREATE_ADHOC))
  {
    if (WIFI.setUDPclient("169.254.194.235",2000,2000))
    {
      // read and send all file lines
      for(int i=0; i < SD.numln(filename); i++)
      {
        // Send messages to another device in same adhoc.
        WIFI.send(SD.catln( filename, i, 1));
        // Receive messages from the other in same adhoc.
        WIFI.read(NOBLO);
      }
      Utils.blinkLEDs(5000);

    }
  }

}

Friday came and the bus arrived to the Headquarters. During the trip we had time for games, jokes... even a karaoke!! When we were arriving to the park, we saw that Dragon Khan, with its loopings and electrifying falls, was not already the current icon of Port Aventura. Shambhala, the new roller coaster, was almost twice than the highest loop of Dragon Khan.

Shambala-dragon
First we took a photo with Woody Woodpecker, Port Aventura's mascot. As you can see, we had a lot of energy to pass a nice day with all team. ;)

Along the day, we get on in all rides, getting funnier. The tests were made in several of them, but the most amazing were Dragon Khan and Shambhala. You can watch the result below.

After this great day in June, we are waiting the Costumes Day that we do in Cooking Hacks each year. You can visit our Facebook page and see the photos of last year. What kind of costumes will be this year? Who will be the winner?

I hope you have enjoyed this article as us.

You can find all information about Waspmote Starter Kit here.
You can take a look on the technical article in Libelium.com

David Bordonada from Cooking Hack's Team

Leave a Reply