Saturday, April 25, 2015

Second degree equation solver with arduino


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
his instuctable is about making sort of a calculator that enables the user by using an analog 12-digit keyboard and 4 buttons to input the a,b,c variables into a equation and get the solution for it if there is any.(well if u don't know what an second grade equation is probably u haven't been in high school, even though you can follow this post to learn about microcontrollers.)

It can be a great electronics class project or an microcontroller starter project.  for your own use.




 

Step 1: Parts list

 
 
 
 
parts.jpg 
 
 
 
 
 
 
 
 
 
 
 
 

arduino board....................http://www.oomlout.co.uk/arduino-duemilanove-p-185.html £24.17
 
medium size breadboard......http://www.oomlout.co.uk/breadboard-830-point-p-250.html £5.11
 
LCD Display (16 x 2)...........................http://www.oomlout.co.uk/lcd-display-16-x-2-p-212.html £7.15
 
4 buttons................................................................................................................$1.00-0
 
1 potentiometer.....................................................................................................$1.00-0
 
 
16x 500ohm, 4x 1k, 1x 6k resistors .................................................................$2.00-1
 
3 green LEDs.........................................................................................................$0.25-0
 
lots of jumpers or striped wires  ........................................................................$1.00-0

And patients!!!!!!

  tip: if u don't have any of this parts it is highly recommended you buy an arduino starter pack that will include almost every electronic part needed, like potentiometers, wires, leds and maybe an lcd. a good one, which i bought ,is http://www.oomlout.co.uk/starter-kit-for-arduino-ardx-p-183.html

 As for the tools, a soldering iron and a wire striper and cutter should be enough.

Step 2:

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
The first thing u have to built is the analog keypad.I will not get into every detail as there is already an instuctable which i followed to make it. http://www.instructables.com/id/Analog-Keypad-Backpack/

 I made it using 500ohm resistors instead of 1k and instead of the 12k resistor a 6k one.(u may want to use this values to have the best chances that the code works without a single variation.I also did not used a stripboard  soldered directly onto the keypads pins which is fairly easy, also i used 2 12k resistor in parallel because i didn't had any 6k at the time.
The resistors needed for this step are 12x 500ohm and one 6k






Step 3: Puting the bread board together

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
First connect the lcd according to the picture the pins used are 2,3,4,5,11,12 .

Then connect the potentiometer and place a jumper to the lcd as shown.

For the buttons and the leds i propose you to follow the way i placed them.

 The leds are connected to pins 15, 16, 17, 18 which in fact are the analog pins A1, A2 ,A3 , A4 and the first three indicate if you have stored a number in the variables a,b,c and the last is the go indicator for the arduino posses the data given and solve the equation.

 The buttons are connected  to pins 6, 7, 8, 9 . the first three  when pressed store the given value to the variables a, b, c and the last signals the arduino to solve the equation.

The last part which needs to be connected apart from the resistors is the keyboarded  that has 3 wires, the the red and the black go to the 5v and the ground. as for the last wire it goes to the analog pin 0. ( A0 ) 

Step 4: The code

Now for the most important part, the arduino code

 All u have to do is to copy and upload it into your arduino and hopefully it should work fine.

The most possible malfunction is that the keyboard may not respond properly. To fix this problem what u have to do is to press the buttons on the keypad one by one and check through the serial display the outputValue1.Then in this form u have to change the numbers (1, 11, 21 ,27......)
if (outputValue1 > 1){
if (outputValue1 > 11){
if (outputValue1 > 21){
if (outputValue1 > 27){
if (outputValue1 > 33){
if (outputValue1 > 38){
if (outputValue1 > 41){
if (outputValue1 > 45){
if (outputValue1 > 47){
if (outputValue1 >= 52){
if (outputValue1 > 54){
if (outputValue1 > 56){
if (outputValue1 > 59){s1 =100;}

so when i pressed  the keys i got the numbers:
                                                           9, 16, 25, 30, 35, 40, 43, 46, 51, 53, 55, 58, 90
and i put middle numbers like  1, 11, 21, 27.....
  if u do the same with the numbers that u are getting it should be easy to fix this.

Step 5: Using it

What you need to do first (after plugging it in of-course) is to insert values a, b, c.
To do this you must first insert the value through the keypad and then press the corresponding button to insert that value into the right variable,( the # button is used to make the number negative so to insert -12 you must press 1, 2, #)  then pres the * button to get back to 0 and program the next variable

Last press the go button and the lcd will show the solution (if the equation has no solution it will display 'impossible' and if every number is a solution it will display 'indefinite'.)
( i don't know if impossible and indefinite is the accurate word to use, please leave a comment and tell me which words should i use.)
Also wait for the video of its operation.

That's it! Now go and make one yourself and have fun with it....
 if u liked my instuctable, please rate it and vote for me in the microcontroller contest (http://www.instructables.com/contest/micro2/?show=ENTRIES ). Also if u have any question feel free to write a comment as i am going to be answering.

Friday, April 24, 2015

Arduino BASIC Shield















Hi all, this is my first instructable documenting the creation of my project, the Arduino UNO BASIC shield which turns the Arduino UNO into a computer running the BASIC programming language.
As microcontrollers are essentially low performance computers on a chip (they have a processor, RAM and ROM) they can be used to create small computer systems. The aim of this project was to use AVR microcontrollers to create a computer capable of running the BASIC programming lanuage.

During learning about the Arduino and creating various sketches, I came across the TinyBASIC project which turns the Arduino into a computer by running a BASIC interpreter. After testing the TinyBASIC sketch on my Arduino UNO, I found the available program memory to TinyBASIC to be fairly low at around 1KB which led me to purchasing an ATmega 1284P. After successfully getting TinyBASIC to run on the 1284P, I found the program memory available to be more than 13KB meaning more than a 13x increase in available memory compared to the Arduino UNO.

Being able to run TinyBASIC on the 1284P then led me to think about standalone computers based on the 1284P and TinyBASIC. I alerted the TinyBASIC sketch to include the TVout library and the PS/2 keyboard library but it would not work (due to the PS/2 library and TVout library not being compatible with each other) meaning I needed a second AVR running either the PS/2 library or the TVout library to allow the computer to function correctly.

I decided to use the Arduino UNO which is based on the ATmega 328 to run the TVout sketch while the 1284P would run the TinyBASIC sketch (with the PS/2 library included); it was done this way around to give TinyBASIC the maximum amount of SRAM possible as TVout requires a RAM buffer.

I knew from previous projects that TVout runs fine on the Arduino UNO and after testing TinyBASIC with the PS/2 library on the 1284P (which worked correctly) I decided to place all components on an Arduino UNO shield.

 

Step 1: Required Components

The components required for the shield PCB are as follows:
1 x ATmega 1284P
1 x DIP40 IC Holder Socket (0.6" wide)
1 x RCA Socket
1 x PS/2 Socket
1 x 470Ω Resistor
1 x 1KΩ Resistor
1 x 220Ω Resistor
1 x 40pin Male Header Strip (to be cut down)
1 x 40pin Female Header Strip (to be cut down)
1 x 5mm LED (This PCB uses an orange LED)
1 x PCB / Arduino Prototype Shield / Stripboard (dependent on how the shield will be made; I created a PCB)

Additionally, solder, a soldering iron, optionally desoldering braid and tools (wire cutters and needle-nose pliers) are needed.

Note this PCB is dual layer. Due to the way I designed this PCB, I also used some 0Ω resistors as jumpers and some tinned copper wires to jump between the layers. The final setup also requires an Arduino UNO, PS/2 keyboard, RCA capable display (such as an LCD TV), RCA cable and a power source (such as a wall mounted PSU).

Step 2: The Circuit

The circuit diagram (and the PCB) were created in the program Fritzing. The circuit diagram is not very complex and consists mainly of the 1284P, PS/2 socket, RCA socket, an LED, some pin headers and some resistors.

The Arduino UNO is responsible for generating a video signal and prints characters received from the serial port to the TV while the 1284P runs TinyBASIC and reads the PS/2 keyboard input. Any input from the keyboard or output from TinyBASIC is sent serially to the Arduino UNO and printed on the connected TV.

After looking at the PS/2 library, the file called "PSKeyboard.h" shows the known interrupt pins of supported AVR microcontrollers (AVR microcontrollers which can run the Arduino bootloader and support this library). An interrupt pin must be used for the keyboard clock line meaning pins 2, 10 and 11 can be used as the clock pin on the 1284P; I chose to use pins 10 and 11 for the data and clock lines of the keyboard.

The TVout library uses pin 7 for video and pin 9 for sync on the Arduino UNO so the RCA socket was connected to the appropriate pin headers. An LED was also included onboard to indicate if the shield was being powered.

TinyBASIC supports the IO pins of the 1284P so these were broken out using female pin headers. Port A (PA0-PA7), port B (PB0-PB7) and port C (PC0-PC7) are connected to female headers to allow the shield to be connected to other devices or components such as LEDs. Two other headers are onboard to allow connections to the power pins (5V and GND) and to allow the serial communication between the 1284P and the UNO to be connected to.

The image shows the circuit diagram with an ATmega 644 (the 1284P and 644 are pin compatible) and the Fritzing project file and circuit diagram PDF can be found attached (as a RAR archive).

Step 3: The PCB















Once the PCB had been designed in the Fritzing program, it was sent to a PCB manufacture to be produced using the isolation milling process. I designed the PCB to be double sided to reduce the number of jumper parts needed and to make the PCB designing process simpler (it would be harder to keep the PCB single sided due to its small size). Also, through hole plating would be needed to keep the PCB single sided as the pin headers need to be soldered on the top side.

As the PCB production process does not have through hole plating, I had to use vias to jump between layers. A small piece of tinned copper wire is placed in the via hole and soldered on either side to make a connection between the top and the bottom layers.

To reduce the number of components in the circuit, no crystal was used as the 1284Ps clock source, instead its internal 8MHz oscillator is used.

One of the images shows a copper coloured PCB. This is a manufacturing reject board as the PCB manufacturers milling machine did not produce this board correctly (the holes are slightly out). The reason this board is copper coloured is because it is not tinned. The tinned PCB was correctly produced and used to create the shield.

An alternative to creating a PCB is to use the Arduino prototype shield or some double sided strip/perf board. Note, the PCB could also be optimised in various ways. The Fritzing file for the PCB is included in the RAR archive on the circuit page.

Step 4: The Firmware


When first testing TinyBASIC on the 1284P it would not run as the SRAM requirements of TinyBASIC exceed the SRAM of the 1284P. To remove this issue, the kRamSize number in TinyBASIC had to be altered by changing this line from:

#define kRamSize  (RAMEND - 1160 - kRamFileIO - kRamTones)

To the following:

#define kRamSize  (RAMEND - 2768 - kRamFileIO - kRamTones)

The higher this number, the lower the SRAM used on the AVR (in this case the 1284P). After the SRAM usage had been lowered to not exceed the 1284Ps SRAM, the PS/2 library was added. The PS/2 header file was added, the clock (irq) and data pins defined and the library started by adding the appropriate code to the setup function.

Without alterations, TinyBASIC uses the serial port for user interaction meaning it needs to be altered to read the keyboard input instead of the serial input. To do this, all calls to "Serial.available()" and "Serial.read()" were replaced with calls to the PS/2 library ("kb.available()" and "kb.read()"). It may be possible to also include the serial reading communications to allow any device connected to the serial header to interact with TinyBASIC but it is currently removed. Serial transmission code was left alone as there was no need to change it (the Arduino UNO reads the serial output of the 1284P and prints to a TV).

The TVout code running on the Arduin UNO simply continuously reads the serial port and if any input is present, it prints it to the TV. Both sketches can be found attached (as a RAR archive).



The bootloader used for the 1284P can be found here: https://www.dropbox.com/s/alywoj4xka0q61v/mighty-1284p-master.zip?dl=0

The original TinyBASIC project can be found here:https://www.dropbox.com/s/i22xy275v7f70st/TinyBasicPlus-master.zip?dl=0

The TVout project for Arduino can be found here: https://code.google.com/p/arduino-tvout/
Please note, TinyBASIC Plus, Arduino software (bootloaders, IDE etc) and TVout all hold there own
 software licences which must be followed if using any of the creators code.

Step 5: Completed Shield







Once the PCB had been designed and manufactured, it was soldered and tested. One issue which arose was serial communications from the 1284P were not being received by the Arduino UNO. To find the cause of this issue, a multimeter was used and a short was found between the TX pin of the 1284P (the RX pin of the Arduino UNO) and ground. Once the short was fixed, the shield operated correctly.

When connecting a TV and a PS/2 keyboard to the shield (as well as a power supply connection), I was met with the TinyBASIC start-up messages which indicate the amount of memory available and the software version showing everything was working OK. The images show the setup with TinyBASIC being displayed on the connected TV and the fully assembled PCB.

Step 6: Future Versions

A future version of the shield could implement the following:
- Ardunio Mega shield (this would allow a greater TVout resolution such as 720x480 - see the update below)
- SD card (this would allow BASIC programs to be stored and run from the SD card)
- Onboard features such as LEDs, potentiometers etc
- Sound support (TinyBASIC has a TONE command which may hold the possibility to allow another RCA socket to be connected to the 1284P allowing simple sound output)

It may also be possible to extend the functionality of TinyBASIC by adding more commands such as communication support (I2C, Serial, SPI etc). A shield for the Arduino Due could also be created (as the Due has much more RAM available for BASIC programs) but this means moving away from 8-bit systems.

Thank you for taking the time to read my instructable. Any feedback is appreciated.

Update:
I have been informed it is not possible for the Arduino Mega to output the resolution of 720x480. This means the second version of this shield (if it was based on an Arduino Mega) would possibly allow higher RCA resolutions due to the higher SRAM compared to the Arduino UNO but it will not allow the resolution of 720x480 to be produced.