Jump to content

  • Log In with Google      Sign In   
  • Create Account

Crawling with ideas



CARDBOARD ROBOTS OF DOOM!

Posted by , in cardboard, silly, Uncategorized, Electronics, Programming, swift, arduino 28 November 2014 - - - - - - · 495 views
electronics, programming, swift and 3 more...
Welcome back!

Last time I have created a software for communicating with my Arduino using HC-05 bluetooth module. Now that I have had that prepared, it was time to do some serious work. It was time to create the robotic arm itself!

Now, I have never done any robots before, so I didn't knew where to start. I've looked at some instructables and saw simple, 3D printed robotic arms. They seemed sensible, but I haven't used CAD software in ages, and I didn't have access to 3D printer anyways, as I currently am staying couple hundred kilometers away from my hackerspace (and haven't yet decided to buy my own 3D printer). I could have done some blind design and just print it out when I would be in Warsaw, but I wanted the robot NOW. So, after looking at the room for scavengable materials, I have decided to take some old box that was lying under table and make robot out of cardboard Posted Image

First I needed a base on which the whole arm would be rotating. I've cut out a small square of cardboard, and in it made a small hole that would hold the base servo:

Posted Image

Now that the first step has been made, it was easier to follow it up. I took a second servo - the one that would be used for angling the main arm, wrapped it in cardboard, and prepared it to put on top of the previous servo via liberal application of scotch tape Posted Image

Posted Image

I have repeated the process twice for main and secondary arm, and it was ready, the CARDBOARD BOT OF DOOM appeared before me:

Posted Image

Now all that was left was testing it. I've tried using it, but the SG92R servos have insane torque for something so small, and the whole robot was flailing around whenever I tried rotating the arm. Again I scanned my surroundings for something to help me, and I found stack of CD-Rs and some small plastic box. I've applied scotch tape yet again, and here is the result:



Next I'll be working in some CAD, probably solvespace or openscad, and try to create something looking bit more professional, hopefully also bit more durable.

Till then, bye!


Ahh! What a fine day, for SCIENCE!

Posted by , in Electronics, swift, arduino 27 November 2014 - - - - - - · 515 views
electronics, swift, arduino
Hello there, journal, long time no see.

As always, I've been busy. Currently doing full time job, running four projects alongside, studying bioinformatics and raising a kid Posted Image

After re-watching Dexter's Laboratory, I felt urge to go back to electronics for a bit. I may not have lab hidden behind bookshelf, but I could do SOMETHING, right? Obviously, after not touching electronics in ages, I barely recalled what's what. First job, as usual, was to make an LED light up. Then I've adde a button that would make the LED light up only when pressed. And then I went into the think tank.

Ever since I was a kid, growing up watching movies, shows and reading books about AI, malicious or otherwise, I was fascinated by it. One of my first projects ever was to write AI in BASIC. Obviously, I was just a kid, and had no idea what I was doing, but seeing 'HELLO, MANTIS' on my old, amber monitor made me really proud. I wanted to create a virtual buddy, a computer which would be my assistant as we discover things for SCIENCE!.

So, what is my project? I want to connect my virtual creations, with reality. The start will be creating camera on a remotely controlled arm. Camera shall be processing images and, depending on software I write, react to them in certain ways. Hell, maybe it'll just HELLO, <INSERT FACE HERE>. That would be nice evolution of what I started all those years ago.

How do I go on with this project? I'll be using Arduino UNO for prototyping, but later I'll probably just etch my own one. My awesome creation will look sort of like this (who needs CAD when you have Paint?):

Posted Image
There will be three to five servos: One to rotate the base, one to angle the base arm, one to angle second arm (second arm is optional), one to rotate camera so that it's level no matter the angle of base arm, and one to rotate the camera around the forward axis - its roll (optional as well). That's the positioning platform. There will be camera attached to the arm, that'll be connected to a processing computer (most likely some kind of rasPi). Computer will recognise the data, and send servo positions to the Arduino.

But how do I send the data? At first, I thought about using nLF24L01 wireless modules to connect between computer and the robot. But that required to create my own wireless dongle to connect to the PC. So I decided to go with WiFi. It would be good to have possibility to connect everything in the lab in a network. But first, I wanted to check out another way of controlling it - via bluetooth. First, I needed to learn how to communicate with bluetooth.

So, first subproject: turn an LED on and off remotely. I have connected HC-05 module to Arduino. The code on the remote side was simple:
#include <SoftwareSerial.h>

SoftwareSerial bluetoothSerial(10, 11);

bool ledState = false;

void setup() {
  // serials
  Serial.begin(9600);           
  bluetoothSerial.begin(9600);
  
  // ledpin
  pinMode(13, OUTPUT);
  setLEDState();
}

void loop() {
    int c = bluetoothSerial.read();
    if (c == 0)
    {
      ledState = !ledState;
      
      setLEDState();
    }
}

void setLEDState() {
      if (ledState) {
        digitalWrite(13, HIGH);
      } else {
        digitalWrite(13, LOW);
      }
      Serial.println("State switched");
}
However, code on the server side gave me troubles. At first, I had to choose the platform I'd be using to control my robot from. Since I was using Bluetooth, at first I thought about creating app for iOS, alas, even though my laptop was detecting the bluetooth module, the iPhone didn't. It turns out that HC-05 is SPP Bluetooth, and iPhone only connects to BLE bluetooth signals. Which means that I was going to need to write software for OS X.

I've decided that it was a good time to polish my Swift skills in a real world project. Using IOBluetooth framework, I've written a simple communications tool. Well, by 'simple', I mean 'it took me wayyy longer than I expected'. I have some problems with interoperability with Objective-C methods, especially with UnsafeMutablePointer<> area, but eventually I've figured it out. So, currently I'm sending an integer from my control project via bluetooth, and when the Arduino receives that integer, it switches the state of LED on pin 13.

Here's a picture of assembled, working circuit:

Posted Image

What's my next goal? Well, I want to have at least couple servos. At first I wanted just to send tuples of [servoID,servoPosition], but then I thought that I may want to add some other things (HD44780 LCD, maybe some LEDs to indicate resonses in real life) to the robot. That would require protocol that is bit more complex, if I want to keep it upgradeable. So, I'll be working on to Arduino that controls couple LEDs, data that controls how long each led should blink. That would basically be the tuple solution. If/when I'll get that working, I'll try sending more data alongside.

See you around!


Pee Oh Vee

Posted by , in Electronics 29 March 2012 - - - - - - · 890 views
POV
Yet another productive day in hackerspace. We're opening 3rd room, as there are plenty new people coming. The walls need to be scraped, the thrash needs to be cleaned, the floor needs to be laid etc. Good thing I wore black blouse and pants today <_<.

Apart from that, I fixed my PSP's thumbstick, which was stuck in off-center position, making killing those Nargacugas in Monster Hunter Freedom Unite horribly hard ( you want to block? tough luck, your character chose this time to start moving. Suddenly, black jumpy death. Now that I fixed it, I'll be able to play MH some more :)

What else? I've continued working on the POV. Obviously to get some kind of cool effects, I'll need some controller. I decided on atmega8 chip. To program one, I'll need a programmer. I used the design from http://thomaspfeifer.net/atmel_usb_programmer.htm . After some time ( and two borked attempts - one using the wrong side, one that didn't copy properly ), I got this sweet sweet thing:

Posted Image

I was ready to create an atmega programmer, but, well, my friend didn't have his programmer. And without a programmer you can't create your own. What do you compile a compiler with? He'll be bringing his sometimes in the weekend, and I'll buy necessary parts on a local electronic carboot sale.

But that didn't stop me: after all, my goal for today wasn't some fancy effect, but rather getting the LEDs to properly display while rotating. And holy shit, I've done it!

Posted Image

Yaaaay! Obviously the picture isn't as pretty as it was when it was running, and there were some problems with continuous display, but for a prototype I'm more than satisfied. To save the copper on the place where brush was running ( as you can see in my previous post ), I've just put loads and loads of solder there - if it'll wear down, I'll just add more ;). But now that I have proof-of-concept version finished, I can start working on the real version. Design it properly, add some box and the controller.

It'll be GLORIOUS :D

See you soon!


Solder of fortune ( yeah, sorry, that was a horrible pun ) megapost

Posted by , in C64, Electronics 26 March 2012 - - - - - - · 944 views
C64, POV
Woah. Today was another long day at the Hackerspace. It's 2:30 AM and I'm finally finished for the day and heading to bed. Just to write this post and it's finally sleepy time. This entry will be quite picture heavy, so those of you who are on 33.6kbps modems may want to take that into account ;). Seeing as it was a long day, the entry will probably quite long - a fair warning. You will however see a whole process of making a PCB, so maybe that's something cool enough to warrant reading through all of this ;)


First of all, guys at the Hackerspace shown me how to properly solder. Since I prefer to do my C64 work on the original machine, as opposed to the emulator ( the 'vibe' is different ;) ), I really wanted to set up one of the Commodores I have at home so that I can code on it. Unfortunately, using the plasma TV was right out, as the monitor cable for C64 is horribly short, and the 42" screen is not something you want to look at while sitting 1 meter from it. Because of that I was forced to code only on emulator. That isn't half bad, as rendering for example those fractals that I described in http://www.gamedev.n...ered-rendering/ took about 15 minutes on 2000-3000% speed of the original machine. Realising how long it would take to render those on real Commodore makes me shudder. Anyways, back to what I was talking about - even though it's slow, it's more awesome, and I want to code on it. So I got my hand on an old, small TV set that I could possibly connect to. The only problem, it didn't have S-Video output, and I had only cable with that output for C64.


Enter soldering! Quick google led me to pinouts.ru, site with hardware pinouts, cables schemes and connectors layouts ( according to their main site). The website had even a full pinout for the exact adapter I was looking for: http://pinouts.ru/Vi...er_pinout.shtml . After quick consult with Ben ( yeah, I guess I should start paying him tantiems or something Posted Image ), I understood what I need to connect where, I looted my box with old parts for cables, sat down and soldered. Here's my creation:

Posted Image


I am quite proud of it, as not only this is the first adapter that I made, but also it is first really usable thing that I created when I needed it, not just for fun. Guys at the HS shown me how to use multimeter, and I checked the cables - all seemed well. I tested it with connecting my Wii through it to the plasma TV, and the image was crystal clear. Sound was also good. SUCCESS! \o/. Unfortunately, it seems that my small TV that I want to use as a monitor for C64 can't be changed to get signal from SCART/EURO without a remote. That is a major setback, but I guess it's also an opportunity - I'll need to get my hands on some IR LED, find the datasheet for the remote in the internet, and emulate its behavior somehow, probably on some Arduino Posted Image.

Now that I started to solder and desolder ( is that even a word? if not, how do you call that activity?) , I went on a rampage. I salvaged any electronic parts that I found in our /dev/null - our bin for anything unused, with primary target being LEDs for my POV display. I found two juicy equilizer displays with plenty of colorful LEDs and cannibalized them. I also acquired quite a few resistors and other usable parts. Yeah, I know those are incredibly cheap, but it's really nice to have start budget of 0.0. It's always easier to make decision to start spending cash on a hobby that you know you're really into.

That or I'm just making excuse for being cheap and lazy Posted Image

Where was I? Oh yes. I got some parts for my POV display. The first prototype was just a CD that I put on top of a small DC motor, to test if it spins fast enough. And honestly, it did. After that I drilled some holes in it, soldered couple LEDs to it , attached them to breadboard with resistors and checked if they worked. And yes, they did. Here's how it looked:

Posted Image

To be quite honest the LEDs didn't work as the machine was spinning, due to the cables cutting through the air like bunch of whips. The prototype obviously needed some work ;).

After thinking it through and talking about it with my friends, I decided to replace the CD with a printed prototype board. It wouldn't have any fixed routes ( except for one ), so I could solder in and out things as I saw fit, start with prototype and grow bigger from that. I launched Eagle, a really cool CAD software that allows you to design boards. Btw: I use free version, which has a limit on board size, but the size that I get with it (100 x 80 mm ) is easily big enough for my needs right now. Anyways, Here's the printed schematic that I quickly put together, already on paper:

http://uploads.gamedev5.net/gallery/album_407/gallery_66033_407_49053.jpg

The dark circle in the middle will be place where brush with current will connect to the board - shaft of the motor will go through the very middle of the board and have ground connected to it, that I will connect back from board through a brush as well. It's not really circular, but I hope that won't cause much problems. Eventually, when I'll be designing dedicated PCB for this, it'll have proper shape. After the print was finished, I cut a piece of board that was bit bigger than the surface I printed, cleaned it properly, and put it through laminator couple times. After the mask got properly stuck, I put it into water for 5 minutes, took the paper off, and landed with this beauty ready to be etched:

http://uploads.gamedev5.net/gallery/album_407/gallery_66033_407_211123.jpg

Well, seems like the transfer process wasn't perfect, but it was good enough for my needs. Another thing I realised was just how freakin' small I made the holes. It was obvious that it'll be hard to solder properly with that tiny copper surface. Nevertheless, I was happy. The board was ready to be etched, I just needed to drill a hole in the side, and off to vat of blue magical chemicals it went:

http://uploads.gamedev5.net/gallery/album_407/gallery_66033_407_186194.jpg

*blob* *blurb* *bloop* it went for couple minutes, etching away the unprotected parts of copper, leaving only those that were covered with paint. Accidentally, the sign on the vat says 'do not drink'. It's smart, regarding we're dealing with CRAZY people in Hackerspace http://public.gamedev.net//public/style_emoticons/default/ohmy.png. I would know, I'm one of them ;). Anyways, the vat did its job and couple minutes later I cleaned the board from the protective ink and had it in my hand - a real life, hand made by me ( well, some parts of it anyways ) PCB. Sweet! It may be not perfect, it may have some problems, but it's my baby ;).

http://uploads.gamedev5.net/gallery/album_407/gallery_66033_407_32326.jpg

Now only to drill OVER 9000 holes. Sheesh. Since it takes ages, I only drilled bunch of them to put necessary pieces in, I'll drill more as it's needed. And yeah, the sockets are so incredibly small that soldering is basically putting a bunch of soldering iron more or less connecting two dots you want to join, and then adding some more. And more. And more. With my noob soldering skills you end up with such hideous results:

http://uploads.gamedev5.net/gallery/album_407/gallery_66033_407_62092.jpg

But again, I'm not bothered by that, as it WORKED:

http://uploads.gamedev5.net/gallery/album_407/gallery_66033_407_23600.jpg

Yay, blinkenlights!

Join me next time, when I'll be hopefully adding the rotation to the device, maybe even add some small controller that will make the lights blink to make pretty patterns!


PWM Receiver

Posted by , in Electronics 25 March 2012 - - - - - - · 995 views
Arduino, Quadcopter
As I'm learning more and more about electronics, I have more advanced ideas in my head. Currently my goal is to create a POV display, using motors, servos and shift registers ( which are new stuff I learned about ). However, that's not what I worked on today.

The friend that lent me his Arduino kit is putting together a quadcopter, and he wants it to be Arduino-controlled. He has a FlySky FS-TH9X transmitter that he wants to control the 'copter, and paired FS-R8B receiver that will be used to provide Arduino with information necessary for controlling the flying contraption.

I asked if I can be of any use to him, and he said that indeed I could - I got the job of putting the FlySky controllers to work.

I had absolutely no idea what it's all about, so he gave me a crash course: there are 8 interesting pins on the receiver that I need to connect as arduino inputs, and that the signal is most likely PPM or Pulse Position Modulation, so I should google something about that. The website I found shown that it's a timing based system, where frequency of HIGH signals is used to indicate the value that's transmitted. I asked my friends how to use oscilloscope, because I have never used it before, and I have learned that it's a bit different system. It was PWM or Pulse Width Modulation, not PPM. Instead of frequency of HIGH spikes, HIGH signal lasts for certain time in a loop, and length of that signal can be converted to value. Oscilloscope measurements displayed values of ~1ms for minimum length signal, ~2ms for maximum length signal, and the loop period of 20ms on current controller settings. I only needed to count that and convert to something that could be more intuitive ( I chose a -127 to 127 range, so that it would fit into a signed char ).

I connected all the pins to the inputs 13 to 6, because why not ( naah, just pulling your leg, since I'm communicating through serial with computer, and pins 0 and 1 are used for that communication, I decided to start from other side of board.

With a help of another friend, I quickly put together a code for parsing the pulses into values:


const int minVal = 1000;
const int maxVal = 2000;
char values[8] = {};
unsigned long currentState[8] = {};
unsigned long currentStartCycle[8] = {};
int ch1 = 13;
int ch2 = 12;
int ch3 = 11;
int ch4 = 10;
int ch5 = 9;
int ch6 = 8;
int ch7 = 7;
int ch8 = 6;
int startCycle  = 0;
int currentCycle = 0;

void setup() {			  
  pinMode(ch1, INPUT);	  
  pinMode(ch2, INPUT);	  
  pinMode(ch3, INPUT);	  
  pinMode(ch4, INPUT);	  
  pinMode(ch5, INPUT);	  
  pinMode(ch6, INPUT);	  
  pinMode(ch7, INPUT);	  
  pinMode(ch8, INPUT);	
  Serial.begin(9600);
  startCycle = millis();
  currentCycle = startCycle;

  for ( int i = 0; i < 8; i++)
  {
	values[i] = 0;
	currentState[i] = 0;
	currentStartCycle[i] = 0;
  }
}
void loop()
{
  int currentMicros = micros();

  for ( int i = 0; i < 8; i++)
  {
	// trololo
	if ( digitalRead(13 - i) == HIGH &&
		currentState[i] == 0 )
		{
		  currentState[i] = 1;
		  currentStartCycle[i] = currentMicros;
		}
	// very trololo :>
	else if ( digitalRead(13 - i) == LOW &&
		currentState[i] == 1)
		{
		  values[i] = map ( currentMicros - currentStartCycle[i], minVal, maxVal, -127, 127);		
		  currentState[i] = 0;
		}
  }
  currentCycle = millis();
  if ( currentCycle < startCycle )
  {
	startCycle = currentCycle ;
  
  }

  if ( currentCycle > startCycle + 1000 )
  {
	startCycle = currentCycle;
	for ( int i = 0; i < 8; i++)
	{
	  Serial.print("| Ch");
	  Serial.print(i + 1, DEC );
	  Serial.print(": ");
	  Serial.print(values[i], DEC);	
	}
	Serial.println("");
  }
	
}

And it works! I managed to learn how to do remote control Posted Image. Now, my DeathBots that will help me take over the world are another step closer.

Oh yeah, and here's how my desk looked like ( yeah, just showing off ;) )

Posted Image

Till next time!


Serial connection

Posted by , in Electronics 16 March 2012 - - - - - - · 906 views
Arduino
Today I continued hacking on the Arduino. After setting up the LCD display, I was roaring to do something 'useful' with it. Or at least something cool. I decided on creating a tool that will display amount of free space on hard drives.

I started from the end - made routine on Arduino that takes ints ( or rather longs ) , and displays the data on the LCD. Lots of typing, lots of zeroes and ones ( or highs and lows ), but nothing really challenging. Then I took the 'Serial Monitor' tool that comes with Arduino IDE and started playing around with the Serial routines. That was easy enough and couple minutes later I had a soft that takes incoming bytes and outputs them on the screen. Finally, I've installed VS 11 ( well, the Beta is out and I have formatted my HD recently ), and wrote a tiny console program in C# that takes the first drive and sends the amount of free space on it to COM3 ( which the USB connects as ).

Here's the server code for those of you curious:

using System;
using System.IO;
using System.IO.Ports;
class Info
{
	public static void Main()
	{
		DriveInfo[] drives = DriveInfo.GetDrives();
		// write amount of free space on Drive C:
		long freeSpace = drives[0].TotalFreeSpace / 1024 / 1024;
		SerialPort port = new SerialPort("COM3");
		port.BaudRate = 9600;
		Console.WriteLine(@"Establishing connection");
		port.Open();
		Console.WriteLine(@"Sending data");
		port.WriteLine(freeSpace.ToString());
		Console.WriteLine(@"Closing connection");
		port.Close();
	}
}

Neither this nor Arduino code have any kind of error checking, but I don't give a damn right now. I want to LEARN Posted Image

Right, the Arduino code:


/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
*/

int LED_PIN = 13;
int RS = 2;
int EN = 4;
int D0 = 5;
int D1 = 6;
int D2 = 7;
int D3 = 8;
int D4 = 9;
int D5 = 10;
int D6 = 11;
int D7 = 12;

long hd_free = 0;
void clear_number()
{
  // MOVE TO FIRST DISPLAY
  digitalWrite(EN, LOW);
  digitalWrite(RS, 0);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 0);
  digitalWrite(D6, 0);
  digitalWrite(D7, 1);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);
 
    digitalWrite(EN, LOW);
  digitalWrite(RS, 1);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 1);
  digitalWrite(D6, 0);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);
    digitalWrite(EN, LOW);
  digitalWrite(RS, 1);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 1);
  digitalWrite(D6, 0);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);
    digitalWrite(EN, LOW);
  digitalWrite(RS, 1);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 1);
  digitalWrite(D6, 0);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);
    digitalWrite(EN, LOW);
  digitalWrite(RS, 1);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 1);
  digitalWrite(D6, 0);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);
    digitalWrite(EN, LOW);
  digitalWrite(RS, 1);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 1);
  digitalWrite(D6, 0);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);
    digitalWrite(EN, LOW);
  digitalWrite(RS, 1);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 1);
  digitalWrite(D6, 0);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);
    digitalWrite(EN, LOW);
  digitalWrite(RS, 1);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 1);
  digitalWrite(D6, 0);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);
    digitalWrite(EN, LOW);
  digitalWrite(RS, 1);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 1);
  digitalWrite(D6, 0);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);
 
    // MOVE TO FIRST DISPLAY
  digitalWrite(EN, LOW);
  digitalWrite(RS, 0);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 0);
  digitalWrite(D6, 0);
  digitalWrite(D7, 1);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);
}
void display_text()
{
    // MOVE CURSOR TO RIGHTMOST POSITION
  digitalWrite(EN, LOW);
  digitalWrite(RS, 0);
 
  digitalWrite(D0, 1);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 0);
  digitalWrite(D6, 1);
  digitalWrite(D7, 1);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5); 
 
  // 'M'
  digitalWrite(EN, LOW);
  digitalWrite(RS, 1);
 
  digitalWrite(D0, 1);
  digitalWrite(D1, 0);
  digitalWrite(D2, 1);
  digitalWrite(D3, 1);
  digitalWrite(D4, 0);
  digitalWrite(D5, 0);
  digitalWrite(D6, 1);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);
 
  // 'B'
  digitalWrite(EN, LOW);
  digitalWrite(RS, 1);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 1);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 0);
  digitalWrite(D6, 1);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);
 
    // ' '
  digitalWrite(EN, LOW);
  digitalWrite(RS, 1);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 1);
  digitalWrite(D6, 0);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);
    // 'F'
  digitalWrite(EN, LOW);
  digitalWrite(RS, 1);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 1);
  digitalWrite(D2, 1);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 0);
  digitalWrite(D6, 1);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5); 
 
	  // 'R'
  digitalWrite(EN, LOW);
  digitalWrite(RS, 1);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 1);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 1);
  digitalWrite(D5, 0);
  digitalWrite(D6, 1);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5); 
 
  // 'E'
  digitalWrite(EN, LOW);
  digitalWrite(RS, 1);
 
  digitalWrite(D0, 1);
  digitalWrite(D1, 0);
  digitalWrite(D2, 1);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 0);
  digitalWrite(D6, 1);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5); 
 
 
  // 'E'
  digitalWrite(EN, LOW);
  digitalWrite(RS, 1);
 
  digitalWrite(D0, 1);
  digitalWrite(D1, 0);
  digitalWrite(D2, 1);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 0);
  digitalWrite(D6, 1);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5); 
 
   // MOVE TO FIRST DISPLAY
  digitalWrite(EN, LOW);
  digitalWrite(RS, 0);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 0);
  digitalWrite(D6, 0);
  digitalWrite(D7, 1);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);   
}
void print_memory()
{
 
}
void setup()
{		
  pinMode(LED_PIN, OUTPUT); 
  pinMode(RS, OUTPUT); 
  pinMode(EN, OUTPUT);
  pinMode(D0, OUTPUT);
  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
  pinMode(D3, OUTPUT);
  pinMode(D4, OUTPUT);
  pinMode(D5, OUTPUT);
  pinMode(D6, OUTPUT);
  pinMode(D7, OUTPUT);
  // 8 BIT LCD INIT
  delay(20);
  digitalWrite(EN, LOW);
  digitalWrite(RS, 0);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 1);
  digitalWrite(D5, 1);
  digitalWrite(D6, 0);
  digitalWrite(D7, 0);
  delay(5);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 1);
  digitalWrite(D5, 1);
  digitalWrite(D6, 0);
  digitalWrite(D7, 0);
  delay(2); 
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 1);
  digitalWrite(D5, 1);
  digitalWrite(D6, 0);
  digitalWrite(D7, 0);
  delay(2);
 
  // SET INTERFACE
  digitalWrite(EN, LOW);
  digitalWrite(RS, 0);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 1);
  digitalWrite(D4, 1);
  digitalWrite(D5, 1);
  digitalWrite(D6, 0);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);
 
 
  // ENABLE DISPLAY/CURSOR
  digitalWrite(EN, LOW);
  digitalWrite(RS, 0);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 0);
  digitalWrite(D2, 1);
  digitalWrite(D3, 1);
  digitalWrite(D4, 0);
  digitalWrite(D5, 0);
  digitalWrite(D6, 0);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);
 
  // CLEAR AND HOME
  digitalWrite(EN, LOW);
  digitalWrite(RS, 0);
 
  digitalWrite(D0, 1);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 0);
  digitalWrite(D6, 0);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);
 
 
  // SET CURSOR MOVE DIRECTION
  digitalWrite(EN, LOW);
  digitalWrite(RS, 0);
 
  digitalWrite(D0, 0);
  digitalWrite(D1, 1);
  digitalWrite(D2, 1);
  digitalWrite(D3, 0);
  digitalWrite(D4, 0);
  digitalWrite(D5, 0);
  digitalWrite(D6, 0);
  digitalWrite(D7, 0);
 
  digitalWrite(EN, HIGH);
  delay(1);
  digitalWrite(EN,LOW);
  delay(5);
 
  display_text(); 
  clear_number();
 
  Serial.begin(9600);
}
void loop()
{
 
  digitalWrite(LED_PIN, HIGH);   // set the LED on
  delay(100);
  digitalWrite(LED_PIN, LOW);   // set the LED on
  delay(100);
  int incoming = 0;
  int power = 0;
  hd_free = 0;
  if ( Serial.available() > 0 )
  {
    clear_number();
    while ( Serial.available() > 0 )
    {
	  incoming = Serial.read();
	  if ( incoming >= 0x30 && incoming <= 0x39 )
	  {
	    if ( incoming == 0x30 )
	    {		 
		  hd_free = hd_free * pow(10,power) + 0;
		 
		  digitalWrite(EN, LOW);
		  digitalWrite(RS, 1);
		 
		  digitalWrite(D0, 0);
		  digitalWrite(D1, 0);
		  digitalWrite(D2, 0);
		  digitalWrite(D3, 0);
		  digitalWrite(D4, 1);
		  digitalWrite(D5, 1);
		  digitalWrite(D6, 0);
		  digitalWrite(D7, 0);
		 
		  digitalWrite(EN, HIGH);
		  delay(1);
		  digitalWrite(EN,LOW);
		  delay(5);
	    }
	    else if ( incoming == 0x31 )
	    {		 
		  hd_free = hd_free * pow(10,power) + 1;
		 
		  digitalWrite(EN, LOW);
		  digitalWrite(RS, 1);
		 
		  digitalWrite(D0, 1);
		  digitalWrite(D1, 0);
		  digitalWrite(D2, 0);
		  digitalWrite(D3, 0);
		  digitalWrite(D4, 1);
		  digitalWrite(D5, 1);
		  digitalWrite(D6, 0);
		  digitalWrite(D7, 0);
		 
		  digitalWrite(EN, HIGH);
		  delay(1);
		  digitalWrite(EN,LOW);
		  delay(5);		 
	    }
	    else if ( incoming == 0x32 )
	    {		 
		  hd_free = hd_free * pow(10,power) + 2;
		 
		  digitalWrite(EN, LOW);
		  digitalWrite(RS, 1);
		 
		  digitalWrite(D0, 0);
		  digitalWrite(D1, 1);
		  digitalWrite(D2, 0);
		  digitalWrite(D3, 0);
		  digitalWrite(D4, 1);
		  digitalWrite(D5, 1);
		  digitalWrite(D6, 0);
		  digitalWrite(D7, 0);
		 
		  digitalWrite(EN, HIGH);
		  delay(1);
		  digitalWrite(EN,LOW);
		  delay(5); 
	    }
	    else if ( incoming == 0x33 )
	    {		 
		  hd_free = hd_free * pow(10,power) + 3;
		 
		  digitalWrite(EN, LOW);
		  digitalWrite(RS, 1);
		 
		  digitalWrite(D0, 1);
		  digitalWrite(D1, 1);
		  digitalWrite(D2, 0);
		  digitalWrite(D3, 0);
		  digitalWrite(D4, 1);
		  digitalWrite(D5, 1);
		  digitalWrite(D6, 0);
		  digitalWrite(D7, 0);
		 
		  digitalWrite(EN, HIGH);
		  delay(1);
		  digitalWrite(EN,LOW);
		  delay(5); 
	    }
	    else if ( incoming == 0x34 )
	    {		 
		  hd_free = hd_free * pow(10,power) + 4;
		 
		  digitalWrite(EN, LOW);
		  digitalWrite(RS, 1);
		 
		  digitalWrite(D0, 0);
		  digitalWrite(D1, 0);
		  digitalWrite(D2, 1);
		  digitalWrite(D3, 0);
		  digitalWrite(D4, 1);
		  digitalWrite(D5, 1);
		  digitalWrite(D6, 0);
		  digitalWrite(D7, 0);
		 
		  digitalWrite(EN, HIGH);
		  delay(1);
		  digitalWrite(EN,LOW);
		  delay(5); 
	    }
	    else if ( incoming == 0x35 )
	    {		 
		  hd_free = hd_free * pow(10,power) + 5;
		 
		  digitalWrite(EN, LOW);
		  digitalWrite(RS, 1);
		 
		  digitalWrite(D0, 1);
		  digitalWrite(D1, 0);
		  digitalWrite(D2, 1);
		  digitalWrite(D3, 0);
		  digitalWrite(D4, 1);
		  digitalWrite(D5, 1);
		  digitalWrite(D6, 0);
		  digitalWrite(D7, 0);
		 
		  digitalWrite(EN, HIGH);
		  delay(1);
		  digitalWrite(EN,LOW);
		  delay(5); 
	    }
	    else if ( incoming == 0x36 )
	    {		 
		  hd_free = hd_free * pow(10,power) + 6;
		 
		  digitalWrite(EN, LOW);
		  digitalWrite(RS, 1);
		 
		  digitalWrite(D0, 0);
		  digitalWrite(D1, 1);
		  digitalWrite(D2, 1);
		  digitalWrite(D3, 0);
		  digitalWrite(D4, 1);
		  digitalWrite(D5, 1);
		  digitalWrite(D6, 0);
		  digitalWrite(D7, 0);
		 
		  digitalWrite(EN, HIGH);
		  delay(1);
		  digitalWrite(EN,LOW);
		  delay(5); 
	    }
	    else if ( incoming == 0x37 )
	    {		 
		  hd_free = hd_free * pow(10,power) + 7;
		 
		  digitalWrite(EN, LOW);
		  digitalWrite(RS, 1);
		 
		  digitalWrite(D0, 1);
		  digitalWrite(D1, 1);
		  digitalWrite(D2, 1);
		  digitalWrite(D3, 0);
		  digitalWrite(D4, 1);
		  digitalWrite(D5, 1);
		  digitalWrite(D6, 0);
		  digitalWrite(D7, 0);
		 
		  digitalWrite(EN, HIGH);
		  delay(1);
		  digitalWrite(EN,LOW);
		  delay(5); 
	    }
	    else if ( incoming == 0x38 )
	    {		 
		  hd_free = hd_free * pow(10,power) + 8;
		 
		  digitalWrite(EN, LOW);
		  digitalWrite(RS, 1);
		 
		  digitalWrite(D0, 0);
		  digitalWrite(D1, 0);
		  digitalWrite(D2, 0);
		  digitalWrite(D3, 1);
		  digitalWrite(D4, 1);
		  digitalWrite(D5, 1);
		  digitalWrite(D6, 0);
		  digitalWrite(D7, 0);
		 
		  digitalWrite(EN, HIGH);
		  delay(1);
		  digitalWrite(EN,LOW);
		  delay(5); 
	    }
	    else if ( incoming == 0x39 )
	    {		 
		  hd_free = hd_free * pow(10,power) + 9;
		 
		  digitalWrite(EN, LOW);
		  digitalWrite(RS, 1);
		 
		  digitalWrite(D0, 1);
		  digitalWrite(D1, 0);
		  digitalWrite(D2, 0);
		  digitalWrite(D3, 1);
		  digitalWrite(D4, 1);
		  digitalWrite(D5, 1);
		  digitalWrite(D6, 0);
		  digitalWrite(D7, 0);
		 
		  digitalWrite(EN, HIGH);
		  delay(1);
		  digitalWrite(EN,LOW);
		  delay(5); 
	    }
	    power=1;
	  }	 
    }
    Serial.print(hd_free, DEC);
    Serial.println("");
   
   
  }
}

And here's how it looks running on my machine:

Posted Image

It has enough space for up to 99 TB of free space ;). Theoretically I could have the text scrolling for WAYYYYYY more space ( LCD takes up to 80 characters ). Anyways, now that I made that prototype on Arduino board, I think I'll actually make AtMega8 - based PCB with that capability, just for kicks. A friend from Hackerspace will show me how to make a PCB, and that seems as good project as any to have for my first device.

See you around!


Arduino hacks

Posted by , in Electronics 15 March 2012 - - - - - - · 942 views
Arduino
As some of you know, I'm heavily influenced and inspired by our own Ben Ryves's awesome work, especially his awesome Z80 computer ( http://benryves.com/journal/3691543 notice how he named it 'A useful Z80 computer'. Useful for what, Ben? Posted Image). As such I decided that my work on the Portable C64 can't be limited to only software and started studying hardware / electronics.

Since at Hackerspace I've got access to great many resources that wonderful people there are willing to lend me for studying, I've grabbed Arduino with breadboard ( Sparkfun Inventor Kit to be exact ) and started playing with it. Or I wanted to, but my only computer that I brought there was a FreeBSD machine. And so, from 6pm till 2am I've been trying to set up Arduino to work on FreeBSD. I had major problems with Java, then with permissions, then with port being unresponsive, but mantis does not give up easily, and finally I HAD RESULTS!

Posted Image

Yeah, it's glorious shining LED. Afterwards I played around with series of leds, fading them in and out and started working on something bit more ambitious ( ignoring the 15 tutorials in the booklet ) - I've started working on connecting a HD 44780 LCD to the Arduino. After making a PDF reader from ports ( which btw took ages, it seems that it sucked half of GNOME with it, and my FreeBSD install was quite lean before, running on only Fluxbox ), I started reading its specifications. Finally, I was ready to give it a go, connected the Ground, VCC and contrast adjustment to the arduino, and saw couple characters darken on the display, just as they were supposed to. I connected couple more cables to clear the screen and display the cursor, but suddenly the FreeBSD started acting up again and didn't allow me to put any more soft on the Arduino. Since it was past 6am already, I took my cue to leave Hackerspace ( fortunately I live less than 1km from it Posted Image ), and head home to sleep.

So yeah, 12 hours of work and only picture I've got to show for it is one blinking LED Posted Image


Oh btw, I managed to find an old TV with SCART/EURO connector, which I'm able to connect to my C64, so I don't have to use my plasma to see results of my code on real machine. That's awesome, because honestly, the cable to monitor is so short that I have to sit with face about 1 meter from my, TV, what in case of the huge plasma makes my eyes hide behind my ears.


See you next time!


##################################################

Update:

Now that I got some sleep, I managed to get the LCD working! Not big enough thing to warrant a new entry, but I'm happy to keep you updated Posted Image . I also noticed ( thanks to Ben, again ), that the LCD even if it's single line is divided into two lines, and doesn't automatically jump to the next one, making the text cut off after 8 characters. But I managed to fix that http://public.gamedev.net//public/style_emoticons/default/smile.png

http://uploads.gamedev5.net/gallery/album_407/gallery_66033_407_196907.jpg





August 2016 »

S M T W T F S
 123456
78910111213
14151617181920
21222324252627
2829 30 31   


PARTNERS