Sunday, October 6, 2013

Starting With Android Studio

Over the summer, well at GoogleIO, Google introduced a new way to develop apps for Android, called Android Studio. Android Studio is based on IntelliJ instead of Eclipse. I've been using Eclipse for 7 years, so this change might be a challenge.

The install was really straight forward. Everything is on developer.android.com. The link about halfway down the page will have the various install packages, one for Windows, one for Mac and another for Linux. The only thing these packages don't include is the JDK.

I had a JDK6 installed on my Linux box, and was able to install without any issues. I adjusted my PATH environment variable in the bashrc file, and everything worked the second start (the first start complained about double something being created). Start.sh seems generic, but that is what they use.

Once it came up, there was the tip of the day, and then a warning that there is a new update. There wasn't anything obvious about the update, and how to get the update. I clicked on the "more info" button, and it said to go to help->Check for updates in the menu. I clicked that, and it offered "get updates and restart". The studio GUI went away for about 2 minutes, and gave me status of what is happening. Applying patch was the longest part.

Once it comes up, it starts with a prebuilt app called "My First App". Not sure what it is, but it is a place to start.

The developers page has a link to some tips. These tips offer easier ways to do some editing, and navigation using control keys like emacs and other editors.

The layout editor give an easy start, but isn't intuitive. I added a button, and it looked like it was attached top and center. When I re-sized the button, it jumped to the upper left. The proper way to re-size the button was to change the text and font. I'll have to play with that a little more, so I can figure out how to align buttons and such (assuming I have an app with many buttons).

Most of the default devices are Nexus, and generic low resolution ones. I don't think a 5.4" screen will likely come in 480x854 pixels. I created a Galaxy NoteII with a 5.5" screen at 1280x720 pixels, since that is a phone I use. It doesn't reall matter, since whatever you create will just change presentation on the different devices.

At the top of the edit area, are tabs for the editable stuff, and at the bottom are the tabs for the view. The view can be changed between "Design" and "Text". Design is the drag and drop part. Text is the place where the XML and Java are edited for the project. The java code is where the callbacks and such go. The XML is where the properties of the display is set. While much of the screen layout can be adjusted in the drag-n-drop section, sometimes certain tweaks require editing the XML.

Building is easy, pressing the build menu, and selecting make project will create a set of executables that can be used to build an APK file. The APK file must be signed with a given key. Either a self signed key, or an official key from a register can be used. To self sign an app for testing, you can use the Keytool.

Once your app is running in the emulator (and maybe on a device), the adb tool can be displayed. Selecting on the Android in the bottom part of the frame, or selecting run->debug from the top menu, will enable debugging.

This is a powerful tool. Android Studio has many options, and will take some getting used to. It may not happen the first time you use the tool, or the second time, but it will be a good tool to use.

Give it a shot!



Sunday, September 22, 2013

Samsung isn't Great


I was all excited about the Samsung infrastructure, but I see some big cracks. I've got the Galaxy NoteII and the Galaxy Note 10.1. My wife also has the Galaxy NoteII. Don't get me wrong, Samsung builds great hardware.

Samsung software is not so great! They go a real strong 90% of what someone needs. I think as long as you stay in the Samsung family, things get along. Once outside, well, that is when the trouble starts. I've never signed up for any of the Samsung services, since I was already signed up for the Google services that meet my needs.

Things like Peel, gosh what a great little app for knowing what is happening on the TV networks. Easy to program and easy to get all setup. They sent out an update (I didn't think it needed it, but I took the update, and then the IR didn't work so well on one TV. I reset up that TV, and then it worked again, but why did the update break things???

The other feature of the Notes, are the pens. Wow, how cool is that. There have been no updates to the SNote software since I got the units, and the software is almost there. The text recognition is wonderful, no training, and it was recognizing my chicken scratches almost perfect. My problem is with the text boxes. Why can't the text boxes be more automatic. They come up small, and aren't easy to resize, and don't always put spaces between words. That makes the software, close to unusable.

I use the SNotes to take written notes, and don't bother to convert to text. That removes the search capability. I say I'll get to converting the written text to either a blog post or a wiki entry for my work documents. But that will add work, and may not help long term.

I feel Samsung pollutes the systems with crapware too. The AllShareCast dongle app is probably really useful if you have an AllShareCast dongle, but I don't. Why can't they make that an optional app instead of requiring it on all devices. ChatOn, SamsungLink and SamsungPushService all seem benign, but I need to keep those things up to date, in case there are exploits in the current version. (If you want a laugh, look in the playstore for reviews of SamsungLink). Why don't they make their services compelling, rather than same or worse than what I have today.

So now Samsung releases Gear. What a bad joke! It only works with the newest Samsung devices (for now??). The NoteIII and the newest Note 10.1. Dang you mean I need to update all my hardware to use a watch that might work for a day? I don't think so. This silly watch can't be very useful, since it has a tiny screen, and can't really talk to the outside world without a tablet or phone. Battery life of 25hours, well, hmmm... I better not spend the night at a friends house unless I brought a charger. And why not a wireless charger?

Now Samsung wants to start a whole new infrastructure. They want people to look at Tizen as a replacement for Android. Cool! their apps are so good, why not have me looking at devices based on Tizen, they will be better than...a sharp stick in the eye, I guess. (where is that sarcasm tag??)

No, I think my next device will NOT be Samsung. They don't have to do much to fix things in the next year, they only need to make what they have usable. Going for the next big thing is great, if they did it great. They haven't done anything great so far, and I don't seem 'em going that way. They will continue to do things that look like they could do things great, and will continue to disappoint. Unless they actually do great things, they will start being another mediocre phone company.

Samsung will need to support current devices, and make improvements. The Note line is clearly different than any other phone/tablet available, and they can build on that by fixing the software! Samsung has a reputation of crapifying phones, and if they quit doing that going forward that would help their reputation. By removing the crap, they may have an incentive to make their apps compelling, and people will want them, and actually install them. Today, all the owners of Samsung devices are forced to have the crap preloaded, and all we want to do is remove it!

It is up to you Samsung!

Sunday, August 4, 2013

The Mask is Off By One

A common software mistake, off by one errors happen occasionally. Indexing starting at 0 instead of one, you got ten things, so the last on is 9, not 10. What about hardware, you go pins, and they are numbered, or sometimes labeled. Dang it, wouldn't you know it, the labels on the board were off by one.

If you look at those labels, you can see the ground and 3.3V labels and that is where I am connected. Trouble is, if you look on the board this shield plugs into, the labels are off by one.

Starting with the pin labeled 5.0V on the shield, that is connected to RESET on the MEGA128 board that I am using. The next pin, is labeled  3.3V, but the traces in front of it are connected to the 5V. The next pin, labeled GND but the trace in front of it is really 3.3V. See these two pictures.

I believe I may have cooked my chip. All I could get out of the code was a 0. Over and over again. I should check the other writing to make sure I am connected to the proper pins. 


I have a spare MAX31855, so I am not totally dead in the water yet. I want to connect it to the right voltage, incase it does a shutdown on over voltage, and not leak smoke only. (I never saw any smoke).

Unsoldering the chip may be possible as well.

I really am trying, I just kept fiddling with the software, until tonight when I checked the voltage. (trust me the software is monkey see monkey do. I am using the SPI library included with the Arduino code.

I am an idiot. The 50, 51, 52 ... pins at the end start with 2 ground pins. I didn't count. So it is completely wired wrong. I need to take another whack at that part before I get around to calling my chip bad.

I am blaming it on being out of hardware practice. Can you take 5 years off from something and pick it up in a weekend.

Ever be so dumb yourself?

I re-did the connections. I am, using the ICSP header for both the SCLK and MISO. I've got it connected to 3.3V and it seems to be outputting data. 0 with nothing connected and some random data when the thermocouple is connected.

I've found the Adafruit libraries for the MAX31855, and want to try them, but am out of time for tonight. I'll get to looking at them another evening when I have more time. 

Monday, July 15, 2013

Chips Are Getting Smaller

I started building with integrated circuits in about 1976. Radio Shack started carrying the 7400 series chips sometime around then. In school I had learned about half and full adders, so I knew what AND, OR and NOT gates were. I imagine they were a couple bucks each back then, but I wanted to build something. I quickly soldered up a half adder using these chips on a piece of Formica, dead bug style.

Over the years I built many projects hand soldering huge boards of chips. In high school, me and three other guys (Scott and Steve) built Don Lancasters TV Typewriter II. We etched the board our selves, but without plated through holes, ended up soldering sockets on both sides of the board (Steve pulled his hair out troubleshooting the thing, eventually removing about half the sockets, soldering the chips in, on both sides). I built many expander boards for the various computers I've had in the last 40 years.



Tonight I soldered in the MAX31855KASA chip I got as a sample a couple months ago. Fun, cool, challenging. I cleaned the heck out of the soldering iron, had to refile the tip to get it sharp enough, and it happened. The first time, I got 4 of 8 pins, the second time I got 6 of 8, and finally with some heat, I got the other two. It doesn't look pretty, but it works, and no shorts. Mass production will require solderflow, if I am to use these chips.



Yesterday and today, I did some research. Yes, the Arduino supports SPI. There is a nice SPI reference library as well. The MAX31855 only does serial out, so I connected the pins like:

   44  - IO44  - Chip Select of the 31855
   50  - MISO  - Serial out of the 31855
   52  - SCK - Serial clock input of the 31855

I used my standard color coding, that I have been doing for over 30 years:
   Blue - Ground
   Red - Vcc
   White - Signal

Then the rainbow ribbon cable is:
   Red - T+ Thermocouple +
   Orange - T- Thermocouple minus

The results look a little messy:
   

I am a little nervous that the chip is at one end of the board and the SPI is at the other end, but that is the layout of this proto board. There is only one thermocouple input in this chip, so that also disapoints me, but who knows, working in eagle, and maybe it won't matter. 

I tested the K-thermocouple that I have using a soldering iron and my vold meter. It is hard to read the voltage in the meter, but it looks like 15mv:



I haven't written the code yet, but I'd like to as soon as I can. Maybe tomorrow. 


Sunday, July 14, 2013

Amarino - Again

So I switched back to Amarino. Nothing wrong with the Andruino, in fact long term I'll probably base things off of that, I just need a GUI on the Android now, and Andruino doesn't let me do that. Code that I write for Amarino will be portable for the most part, so I should be able to write a gage module and use it for both environments.

So I rewound... I didn't go to the trouble of connecting the old PC hard disk to the new computer. I thought I would learn more if I did it the hard way. So far I think I have. Amarino isn't very flexible. The code must be hard coded for your bluetooth cards address. Finding the numeric address was a challenge. Initially when the pairing starts it displays the address, but then it changes to the name of the device. I looked in settings, thinking it might list the address there. It turns out the Amarino app has the address in the connect dialog. It took a little while, but I have it.

When I installed the ADK, it defaulted all my targets to 4.2.2. That works great on the emulator, but none of my devices are that advanced. I only have 4.1.2 on them, and some older phones have 2.3.3 or something. (If you aren't familiar with Android, the 2.x OS was pre-tablet version, but you can find some off brand tablets running 2.x, then the 3.x OS was for the early tablets, and Google quickly came up with an OS to satisfy their needs, and it only ran on tablets. The 4.x and above OS is the unified phone/tablet OS that is very current, and is more distributed, so most situations only need a new app, not a whole new OS to get almost all the latest features). The different OS targets APIs are also numbered (IE 4.1.2 is API 16, 2.3.3 is API API 10, sort of like Java versions). 

I installed the 4.0, 4.1 and 2.3 APIs so I can test things out on all my devices. This is done in the Android SDK manager app. Just a few clicks, to select what do download, and press install packages and the ADK is app updated! I didn't download the MIPs or Intel versions, thinking it would save time, and I don't really need them. The older tablets I gave the kids are MIPs based tablets, I may get a version another day for them, if I decide the app is suitable for older tablets (probably, I am not doing anything too complicated, but I don't think those devices have bluetooth).

Loading a bunch of new devices still didn't let me change targets. I had to restart Eclipse. Now I have a large collection of usable APIs. It still can't find my phone, only the emulators. It turns out I needed some new Samsung USB driver for it. I am not sure if Samsung is pushing the boundaries, or if they are being evil requiring a new driver. I'll look into that another day. I installed the app, but now touchwiz keeps crashing. I am rebooting the device, hoping whatever mess I created will get fixed.

Uh oh, now what? Well rebooting didn't fix anything, touchwiz keeps crashing. The phone is useless right now. At least the GUI. It isn't anything malicious, like a virius, just my dopey version of SensorGraph. I can use the notification bar to get to email, and that works (if there is a notification to select). Now when I exit email to go back to the home screen, when touchwiz crashes, I end up back at the email program.

Ooof, sitting here thinking about things, I think I know what I did. The SensorGraph came with an Icon defined in the original package. When I started putting the package together, it couldn't find that icon, so I created a 0byte file for it. I am guessing touchwiz is trying to draw a zero byte icon, and is getting a null pointer exception. I'll change the app to use some other icon, and then download that. It is just touchwiz, so that makes as much sense as anything.

Yes, that fixed that trouble, but now SensorGraph quit at startup. I thought it was because Amarino wasn't running. I started Amarino and connected to the board, then SensorGraph, but it still crashes. The LogCat was enabled, and I see a runtime exception, no class found at.abraxas.amarino.Amarino. It almost sounds like I don't have the amarino libs installed on the phone? Hmmm...

"With great power..." I had the amarino libs included in the build, but not in the deploy. Under the project->properties->buildpath->order and export, I had to check the box to export the amarino libraries. Now it works! Well it is connected, and well, 1 active connection. It says "hello world, sensor graph". I still need to upload the sensor graph software to the arduino. I had already loaded the code to the arduino library. Here is a screen shot of the stock MeetAndroid sketch output on the phone (random noise on analog pin 5)
Then I went and changed the sketch to read the input from the LM34 that was on the board at pin 15
It started at ambient temperatures, then I put my sweaty fingers on it, and you can see where it jumped up.

Now on to redoing my GUI work.






Tuesday, July 9, 2013

I Am Having Fun Now

Okey doke, I am just trying things, and well, it is working. Kinda silly, but at the same time, my juices are starting flowing. The bluetooth is pretty reliable, once I figure out the switches, and such. I've tweaked the Arduino code, and have it doing something interesting.

First the bluetooth, I have the iTead Studio v2.1 bluetooth shield, which seems to be obsolete. There are two switches on the board, voltage selection, and serial port selection. The voltage selection seems to work in either 3.3V or 5V on the Arduino Mega that I am using. The input MUST be set to FT232 for uploading sketches, and in the "To Board" setting to communicate with the Android. Handy to know.

Just as a datapoint, the phone (Samsung Galaxy Note II) seems to pair with the Arduino shield better than the tablet (Samsung Galaxy Note 10.1). I don't know why. The tablet works well once connected, it is just sometimes it is finicky.

I tweaked the sketch to read from the LM34 that I have on the prototyping board from before. This is connected to the A15 pin on the Mega. I have the get data read the value and convert the voltage into something like a temprature. It is running probably 20 degrees warmer than reality if I assume the analog reference is 5V or 10 degrees cool if I assume 3.3V. All I did was put a 1K bias resistor on it, which may be too much, the datasheet shows 50-75ohm. Probably that 3.3V is fine.

 Here is my tweaked code:

/*
 PROJECT: Andruino 0.1 Alpha
 PROGRAMMER: Hazim Bitar (techbitar at gmail dot com)
 DATE: July1, 2013
 FILE: Andruino.ino
 LICENSE: Public domain
*/

#define START_CMD_CHAR '*'
#define END_CMD_CHAR '#'
#define DIV_CMD_CHAR '|'
#define CMD_DIGITALWRITE 10
#define CMD_ANALOGWRITE 11
#define CMD_TEXT 12
#define CMD_READ_ARDUINO 13
#define MAX_COMMAND 20  // max command number code. used for error checking.
#define MIN_COMMAND 10  // minimum command number code. used for error checking. 
#define IN_STRING_LENGHT 40
#define MAX_ANALOGWRITE 255
#define PIN_HIGH 3
#define PIN_LOW 2

String inText;

void setup() {
  Serial.begin(9600);
  Serial.println("Andruino 0.1 Alpha by Tommyb (2013).");
  Serial.flush();
}

void loop()
{
  Serial.flush();
  int ard_command = 0;
  int pin_num = 0;
  int pin_value = 0;
  int temp = 0;    // temprature
  float a15 = 0;  // analog pin 15 input.
  float maxAnalog = 1024;
  float trueTemp = 0.0;

  char get_char = ' ';  //read serial

  // wait for incoming data
  if (Serial.available() < 1) return; // if serial empty, return to loop().

  // parse incoming command start flag 
  get_char = Serial.read();
  if (get_char != START_CMD_CHAR) return; // if no command start flag, return to loop().

  // parse incoming command type
  ard_command = Serial.parseInt(); // read the command
  
  // parse incoming pin# and value  
  pin_num = Serial.parseInt(); // read the pin
  pin_value = Serial.parseInt();  // read the value

  // 1) GET TEXT COMMAND FROM ANDRUINO
  if (ard_command == CMD_TEXT){   
    inText =""; //clears variable for new input   
    while (Serial.available())  {
      char c = Serial.read();  //gets one byte from serial buffer
      delay(5);
      if (c == END_CMD_CHAR) { // if we the complete string has been read
        // add your code here
        break;
      }              
      else {
        if (c !=  DIV_CMD_CHAR) {
          inText += c; 
          delay(5);
        }
      }
    }
  }

  // 2) GET digitalWrite DATA FROM ANDRUINO
  if (ard_command == CMD_DIGITALWRITE){  
    if (pin_value == PIN_LOW) pin_value = LOW;
    else if (pin_value == PIN_HIGH) pin_value = HIGH;
    else return; // error in pin value. return. 
    set_digitalwrite( pin_num,  pin_value);  // Uncomment this function if you wish to use 
    return;  // return from start of loop()
  }

  // 3) GET analogWrite DATA FROM ANDRUINO
  if (ard_command == CMD_ANALOGWRITE) {  
    analogWrite(  pin_num, pin_value ); 
    // add your code here
    return;  // Done. return to loop();
  }

  // 4) SEND DATA TO ANDRUINO
  if (ard_command == CMD_READ_ARDUINO) { 
    // char send_to_android[] = "Place your text here." ;
    // Serial.println(send_to_android);   // Example: Sending text
    a15 = analogRead(A15);
    // Serial.print(" Analog 15 = "); 
    // Serial.print(a15);  // Example: Read and send Analog pin value to Arduino
    trueTemp = maxAnalog;
    trueTemp = (a15 / trueTemp); 
    Serial.print("  Temp = ");
    Serial.println(trueTemp*330.0);
    return;  // Done. return to loop();
  }
}

// 2a) select the requested pin# for DigitalWrite action
void set_digitalwrite(int pin_num, int pin_value)
{
  switch (pin_num) {
  case 13:
    pinMode(13, OUTPUT);
    digitalWrite(13, pin_value);  
    // add your code here      
    break;
  case 12:
    pinMode(12, OUTPUT);
    digitalWrite(12, pin_value);   
    // add your code here       
    break;
  case 11:
    pinMode(11, OUTPUT);
    digitalWrite(11, pin_value);         
    // add your code here 
    break;
  case 10:
    pinMode(10, OUTPUT);
    digitalWrite(10, pin_value);         
    // add your code here 
    break;
  case 9:
    pinMode(9, OUTPUT);
    digitalWrite(9, pin_value);         
    // add your code here 
    break;
  case 8:
    pinMode(8, OUTPUT);
    digitalWrite(8, pin_value);         
    // add your code here 
    break;
  case 7:
    pinMode(7, OUTPUT);
    digitalWrite(7, pin_value);         
    // add your code here 
    break;
  case 6:
    pinMode(6, OUTPUT);
    digitalWrite(6, pin_value);         
    // add your code here 
    break;
  case 5:
    pinMode(5, OUTPUT);
    digitalWrite(5, pin_value); 
    // add your code here       
    break;
  case 4:
    pinMode(4, OUTPUT);
    digitalWrite(4, pin_value);         
    // add your code here 
    break;
  case 3:
    pinMode(3, OUTPUT);
    digitalWrite(3, pin_value);         
    // add your code here 
    break;
  case 2:
    pinMode(2, OUTPUT);
    digitalWrite(2, pin_value); 
    // add your code here       
    break;      
    // default: 
    // if nothing else matches, do the default
    // default is optional
  } 
}





Whatcha think, any thing I ought to be fiddling with?


Monday, July 8, 2013

I am doing a crummy job...

I am not keeping up with this, I am not documenting what works and what doesn't, and I just ignore all the readers.

Sorry

I'll be very humble in this post. Lots has changed. I bought a new desktop computer. This thing seems really good. It has two USB ports in the front of it, so I think that will help with things. Certainly the arduino plugs in nicely. I have the tablet, and a new phone. They are both Samsung Android devices. This is good, they both share nicely, so I can probably have some success.

Looking back, and trying to get things where I was, well, I am not having any luck.  I reinstalled the Arduino IDE, and looking back at my notes, I guess I missed some setups. The IDE won't let me talk to the board. The driver says successfully installed, but everytime I plug in, I get uh-ah sound from windows. This is Windows7, and I am following the instructions on the Arduino install page.

It seems the Arduino page isn't up to snuff. I went right to the FTDI page for the instructions on how to install the Windows 7 x64 device drivers (I don't think the 64 bit Intel drivers are included with Arduino at this time).  Yes, the instructions appear to make you do the same update driver twice, but yes you need to!

Even wanting to go back to where I was, I don't find any of my software, although it is probably on my old computer. How could you have duplicated, or improved my work? I need to do better than that. I am trying to be more open, and I hope you can understand.

This time the board is a Mega128, and the board is on Com3.  I was able to test this by trying the "Burn Bootloader" option in the tools menu of the IDE and watching the Rx/Tx LEDs blink.

I may go back in grab all the files off that old computer, and then try again, or I may start from scratch?

There seems to be a new Arduino to Android project on Hackaday again. It is using bluetooth, so I will give it a go.

I'll try to keep motivated, and put up code this time.

The Bluetooth device is called linvor 00:11:04:15:10:87, and the login is 1234.  I believe the bluetooth shield is still on 9600 baud.  I keep getting the error:

   avrdude: stk500_getsync(): not in sync: resp=0x00

with the shields on. With the shields off, it works fine. Maybe I need to turn off the bluetooth shield while I am uploading code? There is a switch, one side labeled "to board" the other labeled "to ft232". I can upload the code, with the switch on the "to ft232" side, and get no errors. I can also get serial data from the board to my phone using the serial monitor, without changing the switch. I don't receive anything from the phone though.

This is the code that is included from the Arduino to Android project


/*
 PROJECT: Andruino 0.1 Alpha
 PROGRAMMER: Hazim Bitar (techbitar at gmail dot com)
 DATE: July1, 2013
 FILE: Andruino.ino
 LICENSE: Public domain
*/

#define START_CMD_CHAR '*'
#define END_CMD_CHAR '#'
#define DIV_CMD_CHAR '|'
#define CMD_DIGITALWRITE 10
#define CMD_ANALOGWRITE 11
#define CMD_TEXT 12
#define CMD_READ_ARDUINO 13
#define MAX_COMMAND 20  // max command number code. used for error checking.
#define MIN_COMMAND 10  // minimum command number code. used for error checking. 
#define IN_STRING_LENGHT 40
#define MAX_ANALOGWRITE 255
#define PIN_HIGH 3
#define PIN_LOW 2

String inText;

void setup() {
  Serial.begin(9600);
  Serial.println("Andruino 0.1 Alpha by TechBitar (2013).");
  Serial.flush();
}

void loop()
{
  Serial.flush();
  int ard_command = 0;
  int pin_num = 0;
  int pin_value = 0;

  char get_char = ' ';  //read serial

  // wait for incoming data
  if (Serial.available() < 1) return; // if serial empty, return to loop().

  // parse incoming command start flag 
  get_char = Serial.read();
  if (get_char != START_CMD_CHAR) return; // if no command start flag, return to loop().

  // parse incoming command type
  ard_command = Serial.parseInt(); // read the command
  
  // parse incoming pin# and value  
  pin_num = Serial.parseInt(); // read the pin
  pin_value = Serial.parseInt();  // read the value

  // 1) GET TEXT COMMAND FROM ANDRUINO
  if (ard_command == CMD_TEXT){   
    inText =""; //clears variable for new input   
    while (Serial.available())  {
      char c = Serial.read();  //gets one byte from serial buffer
      delay(5);
      if (c == END_CMD_CHAR) { // if we the complete string has been read
        // add your code here
        break;
      }              
      else {
        if (c !=  DIV_CMD_CHAR) {
          inText += c; 
          delay(5);
        }
      }
    }
  }

  // 2) GET digitalWrite DATA FROM ANDRUINO
  if (ard_command == CMD_DIGITALWRITE){  
    if (pin_value == PIN_LOW) pin_value = LOW;
    else if (pin_value == PIN_HIGH) pin_value = HIGH;
    else return; // error in pin value. return. 
    set_digitalwrite( pin_num,  pin_value);  // Uncomment this function if you wish to use 
    return;  // return from start of loop()
  }

  // 3) GET analogWrite DATA FROM ANDRUINO
  if (ard_command == CMD_ANALOGWRITE) {  
    analogWrite(  pin_num, pin_value ); 
    // add your code here
    return;  // Done. return to loop();
  }

  // 4) SEND DATA TO ANDRUINO
  if (ard_command == CMD_READ_ARDUINO) { 
    // char send_to_android[] = "Place your text here." ;
    // Serial.println(send_to_android);   // Example: Sending text
    Serial.print(" Analog 0 = "); 
    Serial.println(analogRead(A0));  // Example: Read and send Analog pin value to Arduino
    return;  // Done. return to loop();
  }
}

// 2a) select the requested pin# for DigitalWrite action
void set_digitalwrite(int pin_num, int pin_value)
{
  switch (pin_num) {
  case 13:
    pinMode(13, OUTPUT);
    digitalWrite(13, pin_value);  
    // add your code here      
    break;
  case 12:
    pinMode(12, OUTPUT);
    digitalWrite(12, pin_value);   
    // add your code here       
    break;
  case 11:
    pinMode(11, OUTPUT);
    digitalWrite(11, pin_value);         
    // add your code here 
    break;
  case 10:
    pinMode(10, OUTPUT);
    digitalWrite(10, pin_value);         
    // add your code here 
    break;
  case 9:
    pinMode(9, OUTPUT);
    digitalWrite(9, pin_value);         
    // add your code here 
    break;
  case 8:
    pinMode(8, OUTPUT);
    digitalWrite(8, pin_value);         
    // add your code here 
    break;
  case 7:
    pinMode(7, OUTPUT);
    digitalWrite(7, pin_value);         
    // add your code here 
    break;
  case 6:
    pinMode(6, OUTPUT);
    digitalWrite(6, pin_value);         
    // add your code here 
    break;
  case 5:
    pinMode(5, OUTPUT);
    digitalWrite(5, pin_value); 
    // add your code here       
    break;
  case 4:
    pinMode(4, OUTPUT);
    digitalWrite(4, pin_value);         
    // add your code here 
    break;
  case 3:
    pinMode(3, OUTPUT);
    digitalWrite(3, pin_value);         
    // add your code here 
    break;
  case 2:
    pinMode(2, OUTPUT);
    digitalWrite(2, pin_value); 
    // add your code here       
    break;      
    // default: 
    // if nothing else matches, do the default
    // default is optional
  } 
}






To do more testing, I probably need to add some LED's or something.

That is all for tonight, it is getting late.




tom