Sunday, August 5, 2012

Electric Bike (Ebike made with Ecrazyman Controller and Crystalite Motor)

 

So I've been recently playing around with Electric Bikes --- they are awesome! I highly recommend that if you have some free time and about a $1000 dollars lying around that you make your own 50kph (32mph) Electric Bike.

 

Parts for Electric Bike:

  • Crystalite HS3540R Brushless Hub Motor (1500W)
  • Cycle Analyst (for measuring speed and current draw)
  • Hobbyking Lithium Polymer 150W Batteries  (2x)
  • Ecrazyman Brushless  Controller (72v @ 45A)
  • Brat Broodie Bike Used (Any used Bike Frame with Front Suspension)

Monday, April 16, 2012

Arch Linux LXDE /w Xorg Mouse Keyboard on Nook Color Android Tablet

by Thomas Polasek



My goal was simple, install a full linux os on my Nook Color tablet. I was surprised to find out that nobody has bothered to run an Xorg server on the android device itself, practically all solutions went through VNC to access the Xorg server.

I will show you how to boot up an Arch Linux distro with mouse and keyboard support that runs the Xorg server on the linux framebuffer (/dev/graphics/fb0). 





Part 1.

Root your Nook Color

Install Clockwork Recovery Mod

Install the Nook Color Cm7.2-RC1 MiRaGe rom
 http://forum.xda-developers.com/showthread.php?t=1344873

Install the Nook Tweaks app from the google market
 https://play.google.com/store/apps/details?id=com.dalingrin.nookcolortweaks&hl=en

Install the SSHDroid app (optional) from the google market
https://play.google.com/store/apps/details?id=berserker.android.apps.sshdroid&hl=en

Part 2. (Linux OS)

Plug in 4GB+ MicroSD Card (with an Ext4 partition)

Mount the SD Card on your OSX or Linux OS
mkdir -p /mnt/sdcard
mount /dev/sdb1 /mnt/sdcard (Replace /dev/sdb1 with your sdcard device)
Download and Extract Arch Linux distro for ARM7 OMAP to your SD Card
          cd /mnt/sdcard
          mkdir arch
          cd arch
tar xvzf ArchLinuxARM-omap-smp-latest.tar.gz
rm -f ArchLinuxARM-omap-smp-latest.tar.gz

Part 3. 
Connect the MicroSD to your Nook Color Tablet

Run the SSHDroid app or connect via adb shell

Connect to your Nook Color via SSH from your linux machine and make sure our SDCard is writeable/executable
su
bash
cd /mnt/sdcard (this is the mounted directory of your MicroSD card with arch linux on it, yours might be different)
mount -o remount,rw,exec /mnt/sdcard

Chroot into your arch linux distro (you should probably make this a script)
If you need additional/supplementary information here is a good link
http://www.mayrhofer.eu.org/debian-on-android

export mnt=/mnt/sdcard/arch (This is your Arch Linux distro location)

# mount linux essentials to our chroot environment
mount -o bind /dev $mnt/dev
mount -t devpts devpts $mnt/dev/pts
mount -t proc none $mnt/proc
mount -t sysfs sysfs $mnt/sys

# export environmental variables for our chroot
export PATH=/sbin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:$PATH
export TERM=xterm
export HOME=/root
export USER=root

#chroot into our arch linux distro
chroot $mnt /bin/bash

Part 4. (in your arch chroot environment)

Setup our DNS (only have to do this once)
echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 4.2.2.2" >> /etc/resolv.conf

Update arch
pacman -Syu

Install Xorg and LXDE on your Arch Linux Chroot
pacman -S xorg-xinit xf86-video-fbdev xf86-input-evdev lxde

Edit your /etc/X11/Xorg.conf file
cd /etc/X11
rm Xorg.conf
sudo wget http://y.uk.to/files/xorg.conf (or try http://pastebin.com/raw.php?i=8CM7NKhd)
You may need to edit the device references for the keyboard and mouse in Xorg.conf! (/dev/input/event5 and /dev/input/event4 might be different)
More information is found below

Go on your Nook Tablet and Run the Nook Tweaks app
Turn on USB-Settings ---> USB Host Mode
Turn on USB-Settings ---> External VBus

Connect your USB devices to your Nook Color Tablet
Obtain a female to female usb connector
Connect a hub to one side of the female connector
Connect a usb keyboard/mouse to the hub
Connect a mini-usb to the nook and then to the other side of the female connector

If you need to figure out what devices your keyboard and mouse are on, then
cd /dev/input

run the cat command on each input* .... and check if your keyboard/mouse input results in a change on the output from cat
for example, when I press a key on my keyboard cat /dev/input/event5  outputs some binary characters.

Now we will setup our linux framebuffer (****UPDATE 1****)

           pikpok sent me this suggestion in the comments section.
You can use "setprop ctl.stop media & setprop ctl.stop zygote" in adb shell to kill zygote server and media, if you want to return to android you can replace stop with start and run again, it's much better than chmod :)
Now we will setup our linux framebuffer (hack)
Try pikpok's suggestion first, if it doesn't work then try out this hack of mine.
Temporary hack to stop the android system from accessing the frame buffer device. I plan on writing a patch that toggles access to this framebuffer from linux. But right now what I do is
I change permissions on the framebuffer and then wait for the android system to lose connection to the framebuffer device.
Once android loses the connection I run the Xorg server on the framebuffer, it hijacks the graphics output.
If anyone has any idea on a better way to this please feel free to post on the comments section.
Eventually (again this is a hack) the android system will appear to freeze (the screen stops updating)
cd /dev/graphics
chmod 000 /dev/graphics/fb0
chown root:root /dev/graphics/fb0
If the graphics don't freeze right away, then keep running and killing the xorg server over and over until it does.
Start LXDE session (starts Xorg Server)
xinit /usr/bin/lxsession &

If everything is configured good, you will get a full LXDE desktop with mouse and keyboard support.
For any xorg server problems, have a look at the /var/log/Xorg*.log file

To stop the xorg server you can run  (not the safest way but it doesn't really matter for this)
         killall X 

BAM. Fully working linux system using the linux framebuffer with mouse/keyboard support.

In addition to support the USB keyboard and mouse, it is possible for other USB devices that are support ed by linux to be connected. Example of devices such as USB-DVI, USB-SERIAL, Arduino, etc...

Notes about the SD Card and EMMC:
It is possible to chroot into any part of the filesystem of Nook as long as you have rwx access. For my personal usage I chroot into the 8th partition on the EMMC (~4GB) of space and run Arch Linux from there, I find the EMMC runs faster than the SD Card.
****UPDATE 1****
Working on making a full bootable Arch Linux image with the Android Kernel, and without all the Android system fluff.

Tuesday, November 15, 2011

Parsing a text file, sorting lexigraphically and writing the output.

Here is code to parse a text file, sort it, and output it to another file.


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

#define MAX_LINE_LEN 1024

typedef struct{
int arraySize;
int arrayElements;
char ** arrayPtr;
} da_string;

void da_string_Init(da_string * dal, int initialSize){
dal->arrayElements = 0;
dal->arraySize = initialSize;
dal->arrayPtr = (char **)malloc(sizeof(char *)*initialSize);
}

void da_string_Destroy(da_string * dal){
    int i;
    for(i = 0; i < dal->arrayElements; i++)
        free( dal->arrayPtr[i]);

    free(dal->arrayPtr);
    dal->arrayPtr = NULL;
dal->arrayElements = 0;
dal->arraySize = 0;
}

void da_string_AddItem(da_string * dal, char * item){
if(dal->arrayElements >= dal->arraySize){
dal->arraySize *= 2;    
dal->arrayPtr = (char ** ) realloc (dal->arrayPtr,  dal->arraySize * 
sizeof(char *));
}
dal->arrayPtr[dal->arrayElements++] = item;
}

char * da_string_GetItem(da_string * dal, int index){
return dal->arrayPtr[index];
}

int compareAscInt (const void * a, const void * b){
    return ( *(int*)a - *(int*)b );
}

int compareDcsString (const void * a, const void * b){
    return (strcmp(*(char **)b,*(char **)a));
}

FILE *inputFile = NULL;
FILE *outputFile = NULL;

da_string stringArray;

char lineBuffer[MAX_LINE_LEN];

int main(int argc, char *argv[]){
    
    if(argc != 3){
        fprintf(stderr, "error argg\n");
        return -1;
    }
    inputFile = fopen(argv[1], "r+"); //stdin is a valid file stream
    outputFile = fopen(argv[2],"w+");
da_string_Init(&stringArray,10);
    
    while ( fgets (lineBuffer, sizeof(lineBuffer), inputFile) != NULL){
        
        char temp[MAX_LINE_LEN];
        
        int i,j;
        for(i = 0,j = -1; i < MAX_LINE_LEN; i++){
            if(lineBuffer[i] == ','){
                j = i; 
                printf("%d\n",j);
            }
        }
        
        if(sscanf(lineBuffer,"%s",temp) == 1){
            
            int dataLen = strlen(temp) + 1;
            if(dataLen <= 1)
                continue;
            
            char  * data = calloc(dataLen,sizeof(char));
            data[dataLen - 1 ] = 0;
            
            strncpy(data,temp,dataLen);
            
            da_string_AddItem(&stringArray,data);
        }

    }
    qsort (stringArray.arrayPtr, stringArray.arrayElements, sizeof(char *), compareDcsString);
    
    int i;
    for(i = stringArray.arrayElements-1; i >= 0; i--){
        fprintf(outputFile,"%s\n",da_string_GetItem(&stringArray,i));
    }
    
    fclose (inputFile);
    fclose (outputFile);
    
da_string_Destroy(&stringArray);

    return 0;
}

 

Saturday, January 1, 2011

Removing Hal From Gentoo

As you may know already hal has been depreciated, its functionally has been merged with udev. If you are having issues with hal or just want it removed then there are some things you need to know.

  1. The first step to removing hal is to update your USE flags to exclude hal (USE="-hal"). 
  2. Then update your system with emerge --update --deep --newuse world
  3. Now you need to determine what packages require hal, these will have to be removed. Execute: emerge --depclean --verbose --pretend hal. 
  4. You will now have a list of programs that you need to unmerge. In my case gnome-mount. I removed it after checking the dependencies with emerge --depclean gnome-mount.
  5. Now once your system is clean of any dependencies to hal, remove it with emerge --unmerge hal.
  6. Congratulations hal is no longer in control. I recommend you re-emerge xf86-input-evdev before restarting X, if you don't you may run into a situation where your mouse and keyboard are not recognized by X.

Tuesday, December 14, 2010

Interfacing Hantek DSO Oscilloscope with Mac OSX

I had recently bought a Hantek DSO oscilloscope. It is a usb based system written for windows mostly, but thankfully the open source community has developed some software to interface with it.

Running it under linux is possible by using OpenHantek , HantekDSO, or DsoSoda.

Before you can use the oscilloscope on OSX you need to download the firmware... this can be done on Linux using dsoextractfw (found in the open source projects above).

You should obtain two files:  DSO2090_firmware.hex  and DSO2090_loader.hex. (I use a DSO 2090 Oscilloscope obviously)

Now download and compile https://github.com/nall/nexys2-osx/tree/master/fxload. This is the fxload equivalent for OSX.

Connect your DSO to your mac device and run the following command:
./fxload-osx -v -t fx2 -I /Volumes/backy/DSO2090_firmware.hex -s /Volumes/backy/DSO2090_loader.hex -D 0x04b4:0x2090

The -D flag requires the venderID:deviceID as an argument. Your Hantek DSO has a vendorID of 0x04b4 and your model number will be your Hantek DSO Oscilloscope version, which in my case is 0x2090.

If everything went well then your DSO will turn on and start flashing a red light.


I am currently in the process of creating code that will extract data from the HantekDSO. If you are interested in writing your own software then get libusb-legacy from ports. Then extract and compile the code from one of the open source projects. I recommend you use Open Hantek since the code is the most up to date.