Failed Tech Demo

Libraries, utilities, bootloaders...

Failed Tech Demo

Postby Myndale » Sun Aug 10, 2014 12:34 pm

You win some, you lose some.....



Source code as promised:

Code: Select all
// Gamebuino "NFC" Demo - by Mark Feldman (Myndale)
// http://gamebuino.com/forum/viewtopic.php?f=12&t=995

#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;

// how fast to transmit, this demo uses 10 bits per byte (1 start, 8 data, 1 stop)
#define BAUD_RATE 200

// how sensitive the ambient light sensor should be
#define TRIGGER 50

#define DELAY (1000/BAUD_RATE)

#define MENULENGTH 2
const char strTransmit[] PROGMEM = "Transmit";
const char strReceive[] PROGMEM = "Receive";

const char* const menu[MENULENGTH] PROGMEM = {
  strTransmit,
  strReceive,
};

#define MAX_MESSAGE_LENGTH 20
char message[MAX_MESSAGE_LENGTH];
int message_pos;

// use to keep track of ambient light, this value is used to do basic automatic gain
// control so that the demo can work in multiple ambient light conditions
int ambient;

void setup(){
  gb.begin();
  gb.titleScreen(F("\"NFC\" Demo"));
}

void loop(){
  switch(gb.menu(menu, MENULENGTH))
  {
    case -1: //nothing selected
      gb.titleScreen(F("\"NFC\" Demo"));
      break;
     
    case 0:
      transmit();
      break;
     
    case 1:
      receive();
      break;
  }
}

void transmit() {
  strcpy(message, "Hello Gamebuino!");
  gb.keyboard(message, sizeof(message)-1);
  gb.display.clear();
  gb.display.println("Transmitting message:");
  gb.display.println();
  gb.display.println(message);
  gb.backlight.automatic = false;
  gb.display.update();
  pinMode(AMBIENTLIGHT_PIN, OUTPUT);
  digitalWrite(BACKLIGHT_PIN, HIGH);
  ambient = analogRead(AMBIENTLIGHT_PIN);
  gb.sound.playOK();
  wait(3000, false);
  digitalWrite(BACKLIGHT_PIN, LOW);
  while (true)
  {
    if (wait(0, true))
      return;
    if (analogRead(AMBIENTLIGHT_PIN) >= (ambient-TRIGGER))
      continue; 
    if (wait(1500, true))
      return;
    send(message);
    send('\n');
    if (wait(1500, true))
      return;
  }
}

boolean wait(int milliseconds, boolean watch)
{
  long target = millis() + milliseconds;
  do
  {
    gb.buttons.update();
    gb.sound.updatePattern();
    if (watch && any_button_pressed())
    {
      gb.sound.playCancel();
      return true;
    }
  } while (millis() < target);
  return false;
}

void sendBit(int bit)
{
  digitalWrite(BACKLIGHT_PIN, bit ? HIGH : LOW);
  delay(DELAY);
}

void send(char c)
{
  Serial.print(c);
  sendBit(1);    // start bit
  for (int i=0; i<8; i++, c>>=1)
    sendBit(c&1);
  sendBit(0);    // stop bit
}

void send(const char * str)
{
  while (*str)
    send(*str++);
}


void receive() {
  gb.display.clear();
  gb.display.println("Receiving...");
  gb.backlight.automatic = false;
  gb.display.update();
  pinMode(AMBIENTLIGHT_PIN, OUTPUT);
  digitalWrite(BACKLIGHT_PIN, LOW);
  ambient = analogRead(AMBIENTLIGHT_PIN);
  gb.sound.playOK();
  wait(1000, false);
  int low = analogRead(AMBIENTLIGHT_PIN);
  int high = low + TRIGGER;
  int middle = (low + high) >> 1;
  message_pos = 0;
  while (true)
  {
    // wait for start of character
    while (true)
    {
      if (wait(0, true))
        return;
     
      int current = analogRead(AMBIENTLIGHT_PIN);
      if (current >= middle)
      {
        high = current;
        break;
      }
      if (current < middle)
      {
        low = current;
        high = low + TRIGGER;
        middle = (low + high) >> 1;
      }
    }
     
    // read in the character
    delay(2*DELAY/3);
    high = analogRead(AMBIENTLIGHT_PIN);
    middle = (low + high) >> 1;
   
    // stream the bytes in
    char c = 0;
    for (int i=0; i<8; i++)
    {
      delay(DELAY);
      int val = analogRead(AMBIENTLIGHT_PIN);
      if (val > middle)
      {
        c |= (1 << i);
        high = val;
      }
      else
      {
        low = val;
      }
      middle = (low + high) >> 1;
    }
    delay(DELAY);
   
    // test for end of message
    if (c == '\n')
    {
      message[message_pos++] = 0;
      display_message();
      return;
    }
    else if (message_pos < MAX_MESSAGE_LENGTH)
      message[message_pos++] = c;
  }
}

void display_message()
{
  gb.sound.playOK();
  while (true)
  {
    gb.update();
    gb.display.clear();
    gb.display.println("Received message:");
    gb.display.println();
    gb.display.println(message);
    if (any_button_pressed())
    {
      gb.sound.playCancel();
      return;
    }
  }
}

boolean any_button_pressed()
{
  return  gb.buttons.pressed(BTN_A) ||
          gb.buttons.pressed(BTN_B) ||
          gb.buttons.pressed(BTN_C);
}
Myndale
 
Posts: 507
Joined: Sat Mar 01, 2014 1:25 am

Re: Failed Tech Demo

Postby Drakker » Sun Aug 10, 2014 12:43 pm

Ingenious... to bad there is such a variation in screen quality. On my two Gamebuinos the backlights are similar, but one is ghosting like crazy, making it impossible to play games like Crabator, while on the other one contrast adjustments apparently do nothing, although the contrast level it is "stuck" at is very good and works well for all the games on the SD card.

If the Gamebuino had a microphone sound wave modulation could work, speakers are all technically the same. Well, to push it farther, you can use any speaker as a microphone too... can you read from the speaker pins if you go very low level?
User avatar
Drakker
 
Posts: 297
Joined: Sun Mar 30, 2014 2:54 am
Location: Québec, Canada

Re: Failed Tech Demo

Postby Myndale » Sun Aug 10, 2014 12:57 pm

I've been thinking about the speaker myself over the past few days. I'm planning to test it when I get the chance but to be honest I seriously doubt it will work. I can't see it picking up an induced field of any reasonable strength and even if it did the flyback diode used to protect the sound circuit from back-emf would shunt anything higher than the forward threshold voltage of around 0.6V (I think). Whatever was left over would then need to cross the collector-base junction of the drive transistor in order to be read by the speaker pin. I'd love to be proven wrong but I just can't see it working.

One thing that could work though is using Gamebuino in transmit-only mode. In theory the speaker could generate an oscillating field too fast to create sound but at exactly the right frequency to spoof an RFID tag, so you could open door locks that use standard ASK contact-less smart cards and mimic other RFID tag devices. This is also on my "to do" list but I don't have have an RFID reader to test it at the moment. What I do have is a handful of components in a plastic bag marked "RFID reader" which I used about a year ago to breadboard an RFID reader for an Arduino UNO, I see no reason why they couldn't work with Gamebuino. I don't know what actual gaming applications a Gamebuino-based RFID reader would have but hey, it's all part of the fun :lol:

So much to play with, so little free time....
Myndale
 
Posts: 507
Joined: Sat Mar 01, 2014 1:25 am

Re: Failed Tech Demo

Postby treflip » Sun Aug 10, 2014 1:02 pm

Hey Myndale,

How are you (this feel like a work email!)? This is a great concept... I am very impressed with the demo! I look forward to going over the code too!

As a suggestion, what about using the speaker to communicate? If I understand your concept correctly you are using the changing in the PR to indicate data transmission from one device to the other... can the speaker be read from as well?

**I guess not since it's hooked up to a digital pin.... and I just went over the pin the PR is on is an adc too. So it is converting the change in resistance to a digital representation. Maybe other people can understand this too now!

Well maybe someone can improve the code then? I don't know..

Anyway, Thanks for opening up my mind to the idea of data transmission using the light sensor (NFC). I wouldn't have ever thought about that!!!

Have a good day,
Tre

P.s. Haha, I was just about to post this when I wsa told to review your post! Yes, so maybe you can change the speaker pin to a different setting - PD3/INT1/OC2B/PCINT19... I will need to look over these to see if they can be read from in some way... may take a little bit of time for me.

The RFID tag is an awesome additional concept to use the GBO for... I always wanted to listen in on the keys at college and 'see' the data being sent!
treflip
 
Posts: 83
Joined: Fri May 30, 2014 4:50 pm
Location: Florida

Re: Failed Tech Demo

Postby erico » Sun Aug 10, 2014 2:56 pm

Oh my, that is magik!
Great demo, great video. :)
User avatar
erico
 
Posts: 671
Joined: Thu Mar 27, 2014 9:29 pm
Location: Brazil

Re: Failed Tech Demo

Postby rodot » Sun Aug 10, 2014 5:08 pm

That's a great idea, and you actually made it work! Impressive, once again :D
My supplier changed the LED reference without noticing me between the pre-production batch and the 1000pc. batch :oops: on the next batches of Gamebuino the bright back-light will be back!
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Failed Tech Demo

Postby Minest » Sun Aug 17, 2014 1:43 am

Maybe you could ask the user whether the gamebuino is emmiting low, high or medium level light.
User avatar
Minest
 
Posts: 7
Joined: Tue May 06, 2014 9:39 am

Re: Failed Tech Demo

Postby adekto » Mon Sep 08, 2014 7:10 pm

interesting, just wondering but u could use it to write files on the sd card?
instead of using a gamebuino to send you could use the flash of a smartphone
idea behind that would be to have a small IDE on phone to make games on
User avatar
adekto
 
Posts: 448
Joined: Tue Feb 25, 2014 9:47 pm
Location: belgium


Return to Software Development

Who is online

Users browsing this forum: No registered users and 2 guests

cron