HobbyKing.com New Products Flash Sale
Reply
Thread Tools
Old Aug 19, 2013, 05:54 PM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
317 Posts
Build Log
Android and TFT controller for the Full Arduino Control

Hi guys,
Here's a little spin-off from the Full Arduino Control. That tread is more for the coding and basic setup. When you're looking for a small transmitter to use next to your normal transmitter, you don't want to have a big case. You want it light and easy to use (and build). This controller might just fit the bill for that. The TFT is a 2,8" from adafruit. The commands will be send to a second arduino, which handles the transmission. That way I can keep it all quick and easy to modify.

Talking about modifying. In this code I use more strings. That way it's easier for people to change it to their own name, function names and more. You can even choose with which screen you want to start. In the settings menu you can select if you want to see the names, values and debugging. More stuff will be added soon, like channel select.

The sliders allready work for 10 servo's and already have feedback through the serial with the proper command (which are the same as the full control system). When changing screen, the arduino remembers the values and upon returning, you will see the latest settings and values. The R-button resets the slider above it to mid position instantly.

It's a new fresh start. Epprom will also be used again to store key-elements like channels and settings. I'll keep you guys posted. It won't be a small program, but it saves al lot of soldering (about 12 wires total for NRF24L01, serial and battery).

grtz.

Danny

EDIT:
link to full arduino system: http://www.rcgroups.com/forums/showp...3&postcount=85
link to libraries: http://www.rcgroups.com/forums/showp...4&postcount=86

Now for some pictures:



Dutchraptor is online now Find More Posts by Dutchraptor
Last edited by Dutchraptor; Aug 26, 2013 at 07:39 AM.
Reply With Quote
Sign up now
to remove ads between posts
Old Aug 19, 2013, 08:02 PM
---o-O-o---
blutoh's Avatar
United States, NJ, Livingston
Joined Mar 2012
1,604 Posts
Very nice!
blutoh is offline Find More Posts by blutoh
Reply With Quote
Old Aug 20, 2013, 05:58 PM
Registered User
Minnetonka Minnesota
Joined Aug 2007
1,217 Posts
That is really nice Danny, someday I will have see if I can understand it and try it too. I still have the rasberry pi sound system on my list as well. Cap
capricorn is offline Find More Posts by capricorn
Reply With Quote
Old Aug 25, 2013, 07:22 PM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
317 Posts
OK, the Arduino with TFT is nice, but has it's limits.The poor thing needs more memory then a 328 has and a Mega tend to get to big. But, in the other tread somebody said something about a Phone. I first disliked the idea, I've got an android Phone with version 4, it is stable, so I thought: why not give it a new try. First test was nice. Good start, gave hope for more. Since my bluetooth shield was allready configured like they told me on the elecfreaks site, I didn't need pin 8 anymore, so I could use it for the NRF. I now have a Arduino Uno, with a bluetothshield AND a NRF24L01. A bit of stripped down code and now have 2 servo's working and a led that can be turned on/off.

So, here the code, have fun if you decide to try it. I will be uploading newer version with more functions and customizeble look. The servo's still work with presses instead of dragging, but that's somethingI'm working on. At least it's proportional instead of just full left/right/forward/reverse like most youtube movies. As a receiver I just use the receivershield from the full arduino control, as well as it's code. Yes, channelselect will also be possible, controlled from the Phone.

Danny

Arduino code:
Code:
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <SoftwareSerial.h>

#define DEBUG

char buffer[11]; 
const int ledPin =  5;      // the number of the LED pin

// what channel are we on when NOT dynamic set.
int channel = 80;
SoftwareSerial mySerial(2, 3); // RX, TX

int channelsend = 0;
int b;
int channelold;
char msg[140] = "";
int ButtonSend;
int channelchk = 0; 
int timer =0;

// transmit buffering
const int zendbuffer1 = 1;       // how sensitive are the navigationpots in relation to communication
const int zendbuffer2 = 3;       // how sensitive are the other pots in relation to communication
const int transmitbuffer = 5;   // how many millisec. hold for next transmit

// nRF24L01(+) radio attached to SPI and pins 8 & 9
RF24 radio(8,9);
RF24Network network(radio);
// Address of our node
const uint16_t this_node = 1;
// Address of the other node
const uint16_t other_node = 0;

// How often to send to the other unit
const unsigned long interval = 200; //ms
unsigned long last_sent;
long strlnum;


void setup()  
{
  pinMode(ledPin, OUTPUT);      
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  // set the data rate for the SoftwareSerial/Bluetooth port
  mySerial.begin(9600);
    Serial.flush();
    
    SPI.begin();
  radio.begin();
  network.begin(/*channel*/ channel, /*node address*/ this_node); 


}
void loop() {
 if (mySerial.available() > 0) { 
    int index=0; 
    delay(10); // let the buffer fill up 
    int numChar = mySerial.available(); 
    if (numChar>64) { 
      numChar=64; 
    } 
    while (numChar--) { 
      buffer[index++] = mySerial.read(); 
    } 
    splitString(buffer); 
  } 
} 
void splitString(char* data) { 
  
#ifdef DEBUG  
  Serial.print("Data entered: "); 
  Serial.println(data); 
#endif
 
  char* parameter; 
  parameter = strtok (data, " ,"); 
  while (parameter != NULL) { 
    setFUNCTION(parameter); 
    parameter = strtok (NULL, " ,"); 
  } 
  // Clear the text and serial buffers 
  for (int x=0; x<6; x++) { 
    buffer[x]='\0'; 
  } 
  Serial.flush(); 
}

void setFUNCTION(char* data) {   
  network.update();
  char buf[12];
  RF24NetworkHeader header(/*to node*/ other_node);
  
  if (data[0] == '1') { // set group number and within this group do:
    int ledswitch = strtol(data+1, NULL, 10); 
    if (ledswitch == 1){
    int ButtonSend=21128;
    char* xssend = (itoa(ButtonSend,buf,10));
    RF24NetworkHeader header(/*to node*/ other_node);
    const char* ButtonSendCode = (xssend);
    network.write(header,ButtonSendCode,strlen(ButtonSendCode)); 
    delay (transmitbuffer);
    #ifdef DEBUG
      Serial.print(data); Serial.println("  ON");
    #endif
    digitalWrite(ledPin, HIGH);
    }
    if (ledswitch == 2){ 
    int ButtonSend=21000;
    char* xssend = (itoa(ButtonSend,buf,10));
    RF24NetworkHeader header(/*to node*/ other_node);
    const char* ButtonSendCode = (xssend);
    network.write(header,ButtonSendCode,strlen(ButtonSendCode)); 
    delay (transmitbuffer);
      #ifdef DEBUG
    Serial.print(data); Serial.println("  OFF");
    #endif
    digitalWrite(ledPin, LOW);
    }
    
    if (ledswitch >= 1000 && ledswitch <= 1300){
        int servoin1=ledswitch+10000;
        char* xs1 = (itoa(servoin1,buf,10));
        const char* sendready1 = (xs1);
        network.write(header,sendready1,strlen(sendready1)); 
        delay (transmitbuffer);
     #ifdef DEBUG
      Serial.print("Servo X: "); Serial.println(ledswitch-1000);
     #endif
    }
    if (ledswitch >= 2000 && ledswitch <= 2300){
        int servoin2=ledswitch+10000-500;
        char* xs2 = (itoa(servoin2,buf,10));
        const char* sendready2 = (xs2);
        network.write(header,sendready2,strlen(sendready2)); 
        delay (transmitbuffer);
     #ifdef DEBUG   
      Serial.print("Servo Y: "); Serial.println(ledswitch-2000);
     #endif
    }
  }
}
Porcessing code:
Code:
//required for BT enabling on startup
import android.content.Intent;
import android.os.Bundle;

import ketai.net.bluetooth.*;
import ketai.ui.*;
import ketai.net.*;

import oscP5.*;

int stickYM; int stickXMsend;
int stickXM; int stickYMsend;
int overvalue=20; // extra value around fields

KetaiBluetooth bt;
String info = "";
KetaiList klist;
PVector remoteMouse = new PVector();

ArrayList<String> devicesDiscovered = new ArrayList();
boolean isConfiguring = true;
String UIText;
int n = 10;
int nold =1000;
float stickX;
float stickY;
int stvlakX = 100; int stvlakY = 300; // x/y position of main field
int stwidth=500; int stheight=500; // width and height of main field

//********************************************************************
// The following code is required to enable bluetooth at startup.
//********************************************************************
void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  bt = new KetaiBluetooth(this);
}

void onActivityResult(int requestCode, int resultCode, Intent data) {
  bt.onActivityResult(requestCode, resultCode, data);
}

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

void setup()
{   
  orientation(PORTRAIT);
  background(78, 93, 75);
  stroke(255);
  textSize(24);
smooth();

  //start listening for BT connections
  bt.start();
int number = 0;
  UIText =  "d - discover devices\n" +
    "b - make this device discoverable\n" +
    "c - connect to device\n     from discovered list.\n" +
    "p - list paired devices\n" +
    "i - Bluetooth info";
}

void draw()
{
  if (isConfiguring)
  {
    ArrayList<String> names;
    background(78, 93, 75);

    //based on last key pressed lets display
    //  appropriately
    if (key == 'i')
      info = getBluetoothInformation();
    else
    {
      if (key == 'p')
      {
        info = "Paired Devices:\n";
        names = bt.getPairedDeviceNames();
      }
      else
      {
        info = "Discovered Devices:\n";
        names = bt.getDiscoveredDeviceNames();
      }

      for (int i=0; i < names.size(); i++)
      {
        info += "["+i+"] "+names.get(i).toString() + "\n";
      }
    }
    text(UIText + "\n\n" + info, 5, 90);
  }
  else
  {
    background(78, 93, 75);
    pushStyle();
    fill(0);
    rect(stvlakX-overvalue, stvlakY-overvalue, 550,550);
    fill(255);
    ellipse(mouseX, mouseY, 20, 20);
    fill(0, 255, 0);
    stroke(0, 255, 0);
    ellipse(remoteMouse.x, remoteMouse.y, 20, 20);    
    popStyle();
    text("X/Y mouse: \n" +  
    "x: " + nfp(mouseX,0) + "\n" +
    "y: " + nfp(mouseY,0) , 100, 100, width, height);
  }

  drawUI();
}


//Call back method to manage data received
void onBluetoothDataEvent(String who, byte[] data)
{
  if (isConfiguring)
    return;

  //KetaiOSCMessage is the same as OscMessage
  //   but allows construction by byte array
  KetaiOSCMessage m = new KetaiOSCMessage(data);
  if (m.isValid())
  {
    if (m.checkAddrPattern("/remoteMouse/"))
    {
      if (m.checkTypetag("ii"))
      {
        remoteMouse.x = m.get(0).intValue();
        remoteMouse.y = m.get(1).intValue();
      }
    }
  }
}

String getBluetoothInformation()
{
  String btInfo = "Server Running: ";
  btInfo += bt.isStarted() + "\n";
  btInfo += "Device Discoverable: "+bt.isDiscoverable() + "\n";
  btInfo += "Device Discovering:" + bt.isDiscovering();
  btInfo += "\nConnected Devices: \n";

  ArrayList<String> devices = bt.getConnectedDeviceNames();
  for (String device: devices)
  {
    btInfo+= device+"\n";
  }

  return btInfo;
}

/*  UI-related functions */

void mouseDragged() 
{

}


void mousePressed()
{
  // Let's see if the main field is clicked
  if (mouseX >= stvlakX-overvalue && mouseX <= stvlakX+stwidth+overvalue && 
      mouseY >=stvlakY-overvalue && mouseY <=stvlakY+stheight+overvalue){ 
  stickX = map(mouseX, stvlakX, stvlakX+stwidth, 0, 200);
  stickX = constrain(stickX,0,200);
  stickXM = int (stickX); 
  stickXM=stickXM+11000;
  stickY = map(mouseY, stvlakY, stvlakY+stheight, 0, 200);
  stickY = constrain(stickY,0,200);
  stickYM = int (stickY);
  stickYM=stickYM+12000;
  String stickS=""+stickXM+","+stickYM;
  OscMessage sticksend = new OscMessage(stickS);
  bt.broadcast(sticksend.getBytes());
  }
  
  // switch ON/OFF
  if (mouseX <= stvlakX-overvalue || mouseX >= stvlakX+stwidth+overvalue || 
      mouseY <=stvlakY-overvalue || mouseY >=stvlakY+stheight+overvalue){
  if (n != nold){
    nold = n;
String s=""+n;
OscMessage m = new OscMessage(s);
bt.broadcast(m.getBytes());
  }
n++;
if (n>12){n=11;}   
  }
  
  
  //keyboard button -- toggle virtual keyboard
  if (mouseY <= 50 && mouseX > 0 && mouseX < width/3)
    KetaiKeyboard.toggle(this);
  else if (mouseY <= 50 && mouseX > width/3 && mouseX < 2*(width/3)) //config button
  {
    isConfiguring=true;
  }
  else if (mouseY <= 50 && mouseX >  2*(width/3) && mouseX < width) // draw button
  {
    if (isConfiguring)
    {
      //if we're entering draw mode then clear canvas
      background(78, 93, 75);
      isConfiguring=false;
    }
  }
}

void keyPressed() {
  if (key =='c')
  {
    //If we have not discovered any devices, try prior paired devices
    if (bt.getDiscoveredDeviceNames().size() > 0)
      klist = new KetaiList(this, bt.getDiscoveredDeviceNames());
    else if (bt.getPairedDeviceNames().size() > 0)
      klist = new KetaiList(this, bt.getPairedDeviceNames());
  }
  else if (key == 'd')
  {
    bt.discoverDevices();
  }
  else if (key == 'x')
    bt.stop();
  else if (key == 'b')
  {
    bt.makeDiscoverable();
  }
  else if (key == 's')
  {
    bt.start();
  }
}

void drawUI()
{
  //Draw top shelf UI buttons

  pushStyle();
  fill(0);
  stroke(255);
  rect(0, 0, width/3, 50);

  if (isConfiguring)
  {
    noStroke();
    fill(78, 93, 75);
  }
  else
    fill(0);

  rect(width/3, 0, width/3, 50);

  if (!isConfiguring)
  {  
    noStroke();
    fill(78, 93, 75);
  }
  else
  {
    fill(0);
    stroke(255);
  }
  rect((width/3)*2, 0, width/3, 50);

  fill(255);
  text("Keyboard", 5, 30); 
  text("Bluetooth", width/3+5, 30); 
  text("Interact", width/3*2+5, 30); 

  popStyle();
}

void onKetaiListSelection(KetaiList klist)
{
  String selection = klist.getSelection();
  bt.connectToDeviceByName(selection);

  //dispose of list for now
  klist = null;
}
Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Old Aug 26, 2013, 05:14 AM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
317 Posts
Some ideas just keep coming back to haunt me at night. New version for the TFT-shield. Mounted on a Arduino Mega. NRF pin1 -> GND, NRF pin 2 -> 3.3V (some NRF's need 5Volt, check first), NRF pin 3 -> 22, NRF pin 4 ->23, NRF pin5 -> 52, NRF pin 6 -> 51, NRF pin 7 -> 50, NRF pin 8 not connected. Screen P(roportional)1 and P2 are for servo control (incl. reset) and screen 3 for settings.

More to come. Don't forget to have fun.

Danny
Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Old Aug 26, 2013, 03:11 PM
Registered User
tweety777's Avatar
Vlaardingen, The Netherlands
Joined Nov 2008
1,355 Posts
Looks nice!!
More and more ways of controlling a model using Arduinos are being exploited.

Greetings Josse
tweety777 is offline Find More Posts by tweety777
Reply With Quote
Old Aug 27, 2013, 09:46 AM
Registered User
Guard-Officer's Avatar
Canada, ON, Quinte West
Joined Feb 2009
950 Posts
Cool! I'm happy to see your smarter minds are getting into the smart phone stuff. I was hoping this would eventually come, imagine having all the controls for your ship from an App and a plug in accessory transmitter to you receiver you simply hook up the servo's and esc's! This is what I was hoping to see come out of this forum when it started! Keep at it guys! Your what the industry looks at for advancement!

Cheers
G-O
Guard-Officer is offline Find More Posts by Guard-Officer
Reply With Quote
Old Aug 30, 2013, 06:07 AM
Registered User
Deckie's Avatar
Australia, WA, Garden Island
Joined Nov 2010
467 Posts
Very nice work and I'm incredibly enthusiastic to see how this turns out.

Picked up the backlog of parcels from the Mailroom after we hit homeport yesterday, and had that little puppy among it, as well as Ada's Ultimate GPS Shield and two Sparkfun Inertial Measurement Units. My work now continues....

EDIT:

I'm going to try to port your posted code to the Arduino Due with the TFT shield installed......
Deckie is offline Find More Posts by Deckie
Reply With Quote
Old Jun 17, 2014, 09:31 PM
Registered User
Printpix2014's Avatar
Mexico
Joined Jun 2014
7 Posts
Excelente proyecto!!: Palomitas:: Palomitas:
Saludos!
Printpix2014 is offline Find More Posts by Printpix2014
Reply With Quote
Reply


Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Discussion Full RC Arduino Control Dutchraptor Homebrew Hacks for Model Boats 181 Nov 11, 2014 03:02 AM
Discussion Arduino-controlled transmitter Skystream Homebrew Hacks for Model Boats 3 Feb 22, 2013 04:43 PM
Discussion Arduino Uno Based Flight Controller? alexgator Multirotor Electronics 4 Feb 15, 2013 01:49 AM
Discussion controlling brushless motors for arduino afar Multirotor Talk 0 Sep 03, 2012 12:46 PM