Chit chat

———–

Supposedly an update to vim, so I updated my Arch Linux box.

Do mirror this blog to others, so I am not copying someone’s work.

Story about #Munich backing out of #linux is allegely overbloated. http://www.omgubuntu.co.uk/2014/08/munich-council-say-talk-limux-demise-greatly-exaggerated

When it comes to #computers: Amateurs #reinstall. Professionals fix the problem and only reinstall as a last resort. #tech #support

You feel foolish when you have installed applications on a #web server a zillion times, but you make simple mistakes like typing in a url of phpmysql when it should of been phpmyadmin. Been a while, but the app is installed.
#linux
Batch file to slowly print out a text file. Perfect for a quickie teleprompter.
Still use the Chumby for many things. One is a portable Muzak.
As time goes on…..

——————————————————

If you are into arduino type stuff, this may interest you.
Avrian Jump

===========

A very simple ladder language for programming ATMega168s from a web browser.

This started out as a desire to be able to program an [Arduino][] from an iOS device.  Since it doesn’t seem like compiler tools of any sort would get into the app store, I figured something would need to be done in HTML5.  And if a [PC emulator][pcemu] could be written in javascript, so could something like this.

However, recreating the Arduino IDE in HTML seemed like too much work, at least for a first try.  So I reduced the project into something much simpler, while still putting real machine code into the AVR’s flash.  A simple ladder language that compiled into AVR assembly, which would be assembled into machine code, seemed like like a resonable reduction.  With that I could take advantage of the [Audioino][] bootloader, to load right from the web page.

This is still unfinished, go see the TODO file.

Also go read issue #2, playing sounds encoded in data URIs in iOS 5.1 is broken. *sigh*

Try it out! [Avrian Jump](http://tadpol.github.com/Avrian-Jump/avrianjump.html)

Some other ways (likely better) of putting Arduino IDEs into web browsers:
– [wifino](http://www.wifino.com/)

[codebender](http://codebender.cc/)

The Ladder
———-

Each rung on the ladder has a single test and multiple actions.  Tests can check the digital pins, analog pins, and a couple of variables.  Each action can set a digital pin, a PWM output, or a variable.  Analog, PWM, and variables are 16bit values.

There is no ‘setup()’.  Analog pins are always analog inputs.  When specified in a test, a digital pin is set to an input then read.  When specified in an action, it is set to an output then set.

PWM code is still non-existant, so how this will actually work is up in the air.  How I want it to work is:  Specifying a pin in an action as a PWM output makes it a PWM output.  Specifying a pin in a test stops it from doing PWM output.  Specifying a digital state for the pin in an action also stops it from doing PWM output.

There is an ascii format of the ladders.  This was done because it seemed like it could be neat to be able to tweet ladders.  You can view the ascii format, and also load ladders from it.  The ascii parser skips anything it doesn’t recognise; it is a bit too forgiving at times.

An example program:

#Fast Blink LED
:T;A+=1
:A=16383;D13=1
:A=32767;D13=0,A=0

Mostly though, a ladder is converted into AVR assembly.

The Assembler
————-

The assembler is pretty basic. Lots of features commonly found in other assemblers are currently missing.  It does assemble the mneonics from [Atmel’s pdf][avrasm] into machine code.  It supports labels, but not local labels.  It has simple parameter replacement, so common names can be defined for IO registers and memory regions and things.  It can also specify where in memory to put the machine code, and can specify immeadiate words to save in the machine code.

This assembler doesn’t know about the various AVR devices, and so will happily assemble any of the known mnemonics into the output.  Even if your target device has no idea what to do with them.  It has assembled blink tests for the ATmega168 and the ATTiny13, so it seems pretty flexable. (Avrian Jump currently only supports the ATmega168 though.  Maybe add others in the future, but would have to figure the bootloader thing out first.)

Outputs
——-

A ladder can be compiled into a few different formats:

– ASCII
– This the only form can can be converted back into a ladder.
– This is for sharing your ladder with others, or saving a ladder for later.
– S19
– If you don’t have an [Audioino][] bootloader, but still want to use a ladder.  A S19 can be ded with [avrdude][].
– WAV
– A [Audioino][] compatible wav file for loading the ladder onto an ATmega168 with the [Audioino][] bootloader installed.
– Assembler
– This is mostly around for debugging the ladder compiler.  It can be interesting to look at  too.

License
——-

Copyright (c) 2012 Michael Conrad Tadpol Tilstra

Licensed under the MIT License.

[Arduino]:http://www.arduino.cc/
[pcemu]:http://bellard.org/jslinux/
[avrasm]:http://www.atmel.com/atmel/acrobat/doc0856.pdf
[avrdude]:http://ladyada.net/learn/avr/avrdude.html
[Audioino]:http://www.hobby-roboter.de/forum/viewtopic.php?f=4&t=128&p=531

——————————————————

Legacy Robot notes.

Have not made much time to work on special projects. One thing I need to start back on is robopet.  There is nothing real super snazzy about this unit although it could be. Mainly I will use it for carrying snacks back and forth from the kitchen during sporting events. There will be a second level not currently attached to hold the goodies. More information about the unit follows.

Electronics:

Using an old Pentium I computer, usb wireless, DC battery power, dc-dc atx ps and compact flash with an ide conversion interface. Powered wheels came from two Tonka RC cars that I dissected.

Made a special wiring hardness to connect the parallel port with the control electronics. Now I need to start testing the electronics for the motor control. Hoping the h-bridge can take the current. If not, I think I have a IC that will. Worst case scenarios is to do it the old fashion way with transistors. After that, everything should fall into place.

Using a standard power supply to test the unit, but it will run on battery when I finish it. Since the motherboard is AT and the DC-DC PS is ATX, I had to make a special cable from scratch to interface the two. Tested the cable and it works.

Have the wireless working via a usb interface set up to work with a specific router via the mac address and the zone. Albeit the wireless is 11 mb, more than fast enough to receive and send communication

Special home made turn signals to be added also.

No sensors added yet.

Software:

The Linux OS is installed.  The OS resides on a compact flash.The iso file for the version of the Ubuntu distribution also resides on the flash drive and gets mounted as a loop.

Using my own home grown robot control software to gather data from sensors and to operate the unit. Found a binary of the very lightweight web server Boa on launchpad.net for the version of Ubuntu I am using. Installed it. Apache2 is too bulky for this project. Eventually, I want to make an autonomous unit.  This unit will be more like a remote controlled car via wifi.

Code to control the motors has already been tested (using parcon.c) and is working.   Using a hardwired connection, already tested client/server socket programming to communicate with and control the unit. That should be way more efficient and possibly more secure than using a web server per se..

Etc.

Had to make special adapter plates to connect the wheel assemblies to the cart. Originally I used clear plastic, but those broke too easily. Wood worked much better, but not as pretty. Attached a third generic cart wheel.

Extra: We installed ptelnet on an old Palm pda to use it as a dumb terminal. That way we do not have to hook the robot to a monitor when we want to access the unit. Saves electricity and makes it more portable. With the installation of Boa, the Chumby can also be used to control the robot without requiring an umbilical cord. Which means that getting an Android or the like tablet more feasible.

Added schematic for turning blinker.

Links:
http://www.instructables.com/id/Atx-to-At-ps-test-cable/
http://www.instructables.com/id/Linux-beginning-home-automation-on-a-server/
http://www.instructables.com/id/No-solder-parallel-port-break-out/
http://www.instructables.com/id/Mini-parallel-port-break-out-cable/
http://www.instructables.com/id/DB9-serial-break-out-cable/
http://www.instructables.com/id/Vga-breakout-cable/

Parcon.c for controlling parallel port

 #include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/io.h>

char *binprint( unsigned char x, char *buf )
{
  int i;
  for( i=0; i<8; i++ )
    buf[7-i]=(x&(1<<i))?'1':'0';
  buf[8]=0;
  return buf;
}

int main( int argc, char *argv[] )
{
  char c;
  unsigned char val;
  char buf[9];
  int x;
  if( argc<2 )
  {
    printf("  example usage: parcon 1l 2l 3h 5h 8l\n");
    return 2;
  }
  if( ioperm(888,1,1) )
  {
    printf("Couldn't get port 888\n");
    return 1;
  }
  val = inb(888);
  printf("old = %s\n",binprint(val,buf));
  for( x=1; x<argc; x++ )
    if( argv[x][1]!='h' )
      val &= ~(1<<(argv[x][0]-'1'));
    else
      val |= 1<<(argv[x][0]-'1');
 
  printf("new = %s\n",binprint(val,buf));
  outb(val,888);
  return 0;
}

Photos:

------------------------------------------------------

One way to recycle an old case cover.

Variation for pants.

------------------------------------------------------

 If you ever take the time to see what vim can do you would be very surprised.

------------------------------------------------------

Math can be interesting! This is oversimplified, but we can use math for many things. One is that might want to know the position of a motor. In electronics, we might want to know what part of an AC cycle we are in such as reading oscilloscopes. . What is even more interesting, we do not have to have some fancy computer language in most cases to calculate what we need.  Then if you want to, you can port the code to a fancier language and or system.

Sine wave graph

$ ./sine

 cat sine.bas
'rem  ----------------------------
'rem sine wave
'rem -----------------------------
?
?"Sine wave graph"
?
?
?tab(14);"- 1";tab(40);"0";tab(63);"+ 1"
?"Degrees";tab(14);
for j = 1 to 52
    ?"-";
Next j
?
for L = 0 to 360 step 7.5
    let x =  L / 57.19578
    'rem what makes the curve
    let r = sin(x)
    let s = int((r*25) + .5)

          if s<0 then? L;tab(s+40);"*";tab(40);":" 

          if s=0 then ? L;tab(40);"*"
    
          if S>0 then? L;TAB(40);":";tab(s+40);"*"
Next L
end

Cosine graph:

$ cat cosine.bas

'rem  ----------------------------
'rem cosine wave
'rem -----------------------------
?
?"Cosine wave graph"
?
?
?tab(14);"- 1";tab(40);"0";tab(63);"+ 1"
?"Degress";tab(14);
for j = 1 to 52
    ?"-";
Next j
?
for L = 0 to 360 step 7.5
    let x =  L / 57.19578
    'rem what makes the curve
    let r = cos(x)
    let s = int((r*25) + .5)

          if s<0 then? L;tab(s+40);"*";tab(40);":" 

          if s=0 then ? L;tab(40);"*"
   
          if s>0 then? L;TAB(40);":";tab(s+40);"*"
Next L
end

Note: Freebasic was used to compile the code on a Linux based system.

--------------------------------------

Update: For those of you who prefer C,  we found some code for the sine and cosine.

Sine:

$ ./sine

sine.c   (gcc sine.c -lm -o sine)

 

#include <stdio.h>
#include <math.h>

#define WIDTH 60
#define HEIGHT 20
#define X WIDTH/2
#define Y HEIGHT/2
#define XMAX WIDTH-X-1
#define XMIN -(WIDTH-X)
#define YMAX HEIGHT-Y
#define YMIN -(HEIGHT-Y)+1

char grid[HEIGHT][WIDTH];

int plot(int x, int y);
void init_grid(void);
void show_grid(void);

int main()
{
    float x,y;

    init_grid();
    for(x=-3.14159;x<=3.14159;x+=0.1)
    {

// line to change (sin, cos, tan, or etc)

        y = sin(x);
        plot(rintf(x*10),rintf(y*8));
    }
    show_grid();

    return(0);
}

/* Set "pixel" at specific coordinates */
int plot(int x, int y)
{
    if( x > XMAX || x < XMIN || y > YMAX || y < YMIN )
        return(-1);

    grid[Y-y][X+x] = '*';
    return(1);
}

/* Initialize grid */
void init_grid(void)
{
    int x,y;

    for(y=0;y<HEIGHT;y++)
        for(x=0;x<WIDTH;x++)
            grid[y][x] = ' ';
    /* draw the axis */
    for(y=0;y<HEIGHT;y++)
        grid[y][X] = '|';
    for(x=0;x<WIDTH;x++)
        grid[Y][x] = '-';
    grid[Y][X] = '+';
}

/* display grid */
void show_grid(void)
{
    int x,y;

    for(y=0;y<HEIGHT;y++)
    {
        for(x=0;x<WIDTH;x++)
            putchar(grid[y][x]);
        putchar('\n');
    }
}

Cosine:

cosine.c   (gcc cosine.c -lm -o cosine)

 #include <stdio.h>
#include <math.h>

#define WIDTH 60
#define HEIGHT 20
#define X WIDTH/2
#define Y HEIGHT/2
#define XMAX WIDTH-X-1
#define XMIN -(WIDTH-X)
#define YMAX HEIGHT-Y
#define YMIN -(HEIGHT-Y)+1

char grid[HEIGHT][WIDTH];

int plot(int x, int y);
void init_grid(void);
void show_grid(void);

int main()
{
    float x,y;

    init_grid();
    for(x=-3.14159;x<=3.14159;x+=0.1)
    {

// line to change (sin, cos, tan, or etc)

        y = cos(x);
        plot(rintf(x*10),rintf(y*8));
    }
    show_grid();

    return(0);
}

/* Set "pixel" at specific coordinates */
int plot(int x, int y)
{
    if( x > XMAX || x < XMIN || y > YMAX || y < YMIN )
        return(-1);

    grid[Y-y][X+x] = '*';
    return(1);
}

/* Initialize grid */
void init_grid(void)
{
    int x,y;

    for(y=0;y<HEIGHT;y++)
        for(x=0;x<WIDTH;x++)
            grid[y][x] = ' ';
    /* draw the axis */
    for(y=0;y<HEIGHT;y++)
        grid[y][X] = '|';
    for(x=0;x<WIDTH;x++)
        grid[Y][x] = '-';
    grid[Y][X] = '+';
}

/* display grid */
void show_grid(void)
{
    int x,y;

    for(y=0;y<HEIGHT;y++)
    {
        for(x=0;x<WIDTH;x++)
            putchar(grid[y][x]);
        putchar('\n');
    }
}

------------------------------------------------------

The above graphic is nice but what is the date for a particular day. How about the day 214? Supposedly close to the hottest day of the year, then what actual day is that?

Usage: ./main dayofyear year

$ ./main 214 2014
Result: day 214 of year 2014 is '08/02/2014'.

To confirm it:

So it looks like August 2, is near the hottest day of the year.

$ gcc main.c -o main

main.c

 #define _XOPEN_SOURCE /* glibc2 needs this for strptime */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>  
#include <errno.h>

int to_date(
  char * date,
  const size_t size,
  const char * fmt,
  const short unsigned int day_of_year,
  const short unsigned int year)
{
  char buffer[16] = "";

  sprintf(buffer, "%hu %hu", day_of_year, year);

  {
    struct tm t = {0};
    char * presult = strptime(buffer, "%j %Y", &t);

    if ((NULL == presult) || ('\0' != *presult))
    {
      errno = EINVAL;
      return -1;
    }

    strftime(date, size, fmt, &t);
  }

  return 0;
}

int main(int argc, char ** argv)
{
  if (2 > argc)
  {
    fprintf(stderr, "Missing arguments. Usage: %s day-of-year year\n", argv[0]);
    return EXIT_FAILURE;
  }

  short unsigned int day_of_year = atoi(argv[1]);
  short unsigned int year = atoi(argv[2]);
  char date[16] = "";

  if (-1 == to_date(date, sizeof(date), "%m/%d/%Y", day_of_year, year))
  {
    perror("to_date() failed");
    return EXIT_FAILURE;
  }

  printf("Result: day %d of year %d is '%s'.\n", day_of_year, year, date);

  return EXIT_SUCCESS;
}

------------------------------------------------------

 

Light on is a one and light off is a zero.

There is an old joke that says: "There are only 10 types of people in the world: those who understand binary" In any case, it does not hurt to at least look at binary once in a while. Ascii (American standard code for information interchange) is usually eight binary characters of ones or zeroes. So you can take the first 8 ones and zeros for the first character.

Then to further split out the whole code sequence:

01000001 01010010 01010000 01000001 01001110 01000101 01010100

Then you can convert on character at a time.  You can just look at a table or write a program to do it.


</pre>
<pre><code class="language-js"><html>
<head>

<script type="text/javascript">
var input_id = "bin_text";
var answer_id = "answer";

function convertToASCII() {
 var bin_text = document.getElementById(input_id);
 var answer = document.getElementById(answer_id);

 if (!answer) {
  alert("Error: No element with id \""+answer_id+"\".");
  return;
 }
 if (bin_text)
  var text = bin_text.value;
 else {
  error("No element with id \""+input_id+"\".");
  return;
 }
 var divisible = text.length % 8;
 var nonBinary = /[^0|1]/.test(text);
 if (text.length > 0 && divisible == 0 && !nonBinary) {
  var regex = /[0|1]{8}/g;
  var str = text.match(regex);
  var code = 0;
  var placeVal, exp, digit;
  var ascii = '';
  while (str.length > 0) {
   code = 0;
   for (var i=0; i<str[0].length; i++) {
    placeVal = 7-i;
    exp = Math.pow(2, i);
    digit = str[0].charAt(placeVal);
    code += exp*digit;
   }
   str.shift();
   ascii += String.fromCharCode(code);
  }
  answer.innerHTML = "<p class=\"binary\">" + ascii + "</p>";
 }
 else {
  error("Malformed binary.");
  return;
 }

 function error(errText) {
  answer.innerHTML = "<span class=\"error\">Error: " + errText + "</span>";
 }
}
</script>

<style type="text/css">
.block {
 width: 45%;
 border: 1px solid #000000;
 padding: 10px;
}
.binary {
 background-color: #C6FFC7;
 padding: 3px;
}
.error {
 background-color: #FFC6C6;
 padding: 3px;
}
</style>

</head>
<body>

<div style="float:left;" class="block">
 <form onSubmit="convertToASCII(); return false;">
  <p>Enter some binary to decode:</p>

  <input type="text" id="bin_text"/>
 </form>
</div>

<div style="float:right;" class="block">
 <p id="answer"><br/></p>
</div>

</body>
</html></code></pre>
<pre>

------------------------------------------------------

Macaroni maker?

maacaronipress

Good day.

Advertisements