Thursday, August 31, 2017

ATtiny85 Microcontroller - first impressions - excellent

For running motors etc from mobile phones I have been going "old school" analogue with early success with "robot rat" and having a lot of challenges with "robot snake". I had thought that a microcontroller approach would be complex and expensive. This is where the cellphone is the robot "brain" and with one or more microcontrollers as the "spinal cord". I found ATtiny85 boards selling for NZD 3.50, approx USD 2.30). I followed the instructions and everything worked, smoothly and easily. I had the first example program running on this ultra micro computer in 1 hour and I was running my own after another 20 mins.



Excellent instructions on how to program using the Arduino IDE:
https://digistump.com/wiki/digispark/tutorials/connecting

Only advice I would add is that I found it best to stop a program run by pulling out the USB cable and let ATtiny85 go dead for a few minutes while writing the next one - then plug in after starting the new program on the PC. The instructions suggest briefly pull it out and plug it in again when we  run a new program but that gave errors which went away when I did the longer disconnect.

I  am interested in using ATtiny85 to run hobby servos.
I run my first code "sketch" (see below)  - and it gives me 2 pieces of good news:

  1. the "delayMicroseconds()" method works on an ATtiny85
  2. although "delayMicroseconds()" specifies "unsigned int" as the data type, I found it was working OK with common ordinary "int".


int m = 16000;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(0, OUTPUT); //LED on Model B
  pinMode(1, OUTPUT); //LED on Model A  or Pro
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(0, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(1, HIGH);
  //delay(200);
 
  delayMicroseconds(m);  
  delayMicroseconds(m);
  delayMicroseconds(m);
  delayMicroseconds(m);
  delayMicroseconds(m);
  delayMicroseconds(m);
 
  digitalWrite(0, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(1, LOW); 
  delay(3000);               // wait for 3 seconds
}

Wednesday, August 2, 2017

Programming Mobile Phones - Revisit, Review, DroidScript looking good.

An intense weekend programming the test Android Phone. I was making slow progress with the cross-platform tools: Cordova and Xamarin. In the meantime I have been finding that I can prototype a lot of what we want to do with conventional web pages stored on a webserver not needing phone app programming at all.  I need a simple framework, where Android-only is OK, and framework can add phone functions value to my HTML prototypes.  I did a more in depth look at "DroidScript"and it is looking good. I began by trying to work out from the documentation how it could work with an HTML-based user interface, That was inconclusive so I ran it and found immediately that it offers an "HTML App" option which meets my needs very well.

In principle "DroidScript" is like a simplified "Cordova" but "DroidScript" keeps it simple by only supporting Android. The "DroidScript" IDE (Integrated Development Environment) runs completely on the phone although we can run it from a PC via a web interface using a WiFi connection. This lets us drive "DroidScript" with a full screen and keyboard. The IDE is remarkably capable considering it is a download of only 8 Meg compared to the multiple gigabytes of its rivals. It is a good fresh experience to make small edits then test run instantly.

The "HTML App" experience is of an HTML web page, with JavaScript blocks just as we would expect with standard web pages. The only remarkable element is a script import of "app.js" which turns out to be the interface into the phone functions. So it is a very familiar environment with an extended JavaScript which is highly phone capable.

The authors of "DroidScript" are interested in robotics and have done work on getting robotics support into their APIs. "DroidScript" has resources ranging from community contributed sample apps to paid plugins.

"DroidScript" has a home website and an online wiki, but I found it was best experienced, including documentation, by running it on the phone while remoting from the PC. "DroidScript" is a free app from the Google Play store. There are some paid plugins or enthusiasts can get these and support the project via a premium subscription model.