Showing posts with label PYTHON. Show all posts
Showing posts with label PYTHON. Show all posts

Happy Christmas and Happy New Year from Attiny13




While trying to open a chinese camera pen, unfortunately the PCB inside it got damaged. Few of the PCB traces got cut and it became useless. After few days, I removed an 8 pin IC with SO8 package from the PCB. I was curious to know what it is, so I googled the part number 25FW406A but I couldn't find any exact match. I found some part number similar to that and I concluded that it is an SPI flash. Later I got a datasheet from 'ON semiconductor' for a similar part -LE25U40CMD which is a 4M-bit SPI flash memory. I soldered the IC on a common board, powered it with 3.3v and interfaced it to a TI stellaris launchpad via SPI port. According to the datasheet the SPI port need to be initialized in mode 0 or 3. I tried few commands listed in the datasheet and got proper response from the chip, the CHIP ID doesn't matches but that is expected because it is not the same part. I wrote functions for erasing, reading and writing the flash memory and tested it successfully using the launchpad.
       Then I thought of making an audio player using this chip which can play 8K mono wav file for around 1 minute. I selected Attiny13 microcontroller for this project. It is always fun to do some thing with limited resources. Attiny13 MCU is having 1KB flash and 64 bytes RAM. Also it is an 8 pin MCU. There are 5 GPIOs. I don't want to change the reset pin as a GPIO because I want to program it via ISP while developing the firmware.

Running PYTHON (pymite-09) on an Arduino MEGA 2560

Hi, I got a new toy from farnell. It is an Arduino mega 2560 board
in.element14.com/atmel


 

Now it is the first time I am using an arduino board. Arduino mega 2560 is really a great product. The chip got a flash of 256KB, RAM of 8KB and EEPROM of 4KB. Also, the data sheet of Atmega2560 says that we can extend the RAM (by external) upto 64KB. Another most important feature of this stuff is that it have 54 Digital I/O pins (of which 14 provide PWM output). It is clocked with a 16MHz crystal osc. Also the board contains another atmega16 (just above the crystal) which is pre-programmed as a USB to UART converter which enables a serial communitation between the atmega2560 and  PC via USB. The product is shipped with a bootloader inside which make it easy to program it via the same USB-UART channel. So the channel got two functions, ie programming the chip and serial communication with PC. From the arduino home page we can download the arduino IDE for appropriate OS.
      I heard arduino makes people lazy. ;-) But now I understood it is true. Because it is so easy to program an arduino using the arduino IDE. It have an arduino language (it is c++) with a great library functions those are very much user friendly and I heard people saying, "if it is arduino, any one can program it". Now I believe statement is almost right because in arduino IDE, we doesn't need to know any thing about the processor, it's registers and even its real port address also... Every thing is grouped and numbered in the board not according to the real PORTA, PORTB etc but according to it's functioning like PWM, ANALOG, DIGITAL, COMMUNICATION etc.
The arduino IDE got a lot of working examples, what we need to do is, we need to select the board first and then set the serial port and later we can open any example and then simply press 'upload'. It is ready!!!!!!!! ;-)
So no need to explain it more because it is so simple..

Running Python (pymite) on Arduino mega 2560
Appart from the arduino IDE, I would like to use the board seperately to try assembly programming and the normal C programming which I normally used to do using avr-gcc. 1 year ago I heard some one ported python for 8 bit devices but I couldn't use it since I didn't have a chip with enough RAM and flash. But since now I have this arduino mega 2560, I just downloaded pymite (p14p) and I could see a port for arduino mega there. It is nothing but the same "python" programming language written for microcontrollers. It have many limitations but still its interesting to see the python running on this 8 bit chip. I just build it for arduino mega 2560 and was successful (a small trouble was there in building, but any way it's okay).

My own AVR ISP programmer using PIC16f877a and python!

Introduction: 

(don't skip to read the note below)
I recently purchased few AVR microcontrollers. I don't know much about AVR since I am using it for first time. Any way, I have some experience on working with PIC and MSP430. To program AVR using USB, I came to know that USBASP is the best and cheap choice. But any way, I thought of making my own ISP programmer (both PC software and burning hardware) for AVR using my fav PIC (PIC16f877A) microcontroller just for getting familiarised with the process of loading the binary into the AVR flash.
      From PC side, coding is done on python. In short words, the python script reads the hex file (intel hex format) and make some ascii conversion on it and then send it to the PIC16F877A line by line. Now by using some commands for isp programming, the PIC communicate with AVR and transfer the data to it via SPI. I have tested my programmer on atmega8, atmega16 and atmega32.

Note:
 I did this just for learning some thing about the burning process, please don't consider this seriously because this may have many bugs , I don't know and I didn't tested much.. Also I am not interested to continue this because it will be time wasting as there are already many cheap and efficient avr programmers available now. So please don't complain about bugs and don't use this for any important purpose ;-)


 Intel hex format:

Intel hex format is well explained in wikipedia. I learned about it from there. Here is the link towards the wikipedia page. An intel hex file contains the binary information about the flash address and data. It is a text file format. Each line of intel hex file consist of 6 parts. See below picture.

Python maps mouse movements to an led matrix display controlled by a PIC


Introduction:

This is a small "toy paint" on an LED dot matrix display which is controlled by a mouse connected to a PC... We have seen the MS PAINT in windows. This is a small 'TOY PAINT' for my small 8x10 LED dot matrix display :-) Here, using a PC mouse, I could draw and erase picture on a small 80 pixel display made by LEDs. At first I thought of making a mouse controlled robotic arm but due to lack of few mechanical parts, I just postponed that and now made this toy paint as a part of familiarizing  two python modules named pygame and pyserial. The heart of the display is a PIC16F877A micro controller. Now, from the PC side, every thing is done on python. Now, if I am using an RF module in between the PIC and USB to UART converter, I can do the same process remotely... The same idea could be applied in robotics for smooth control of activities remotely using a computer mouse...

Bulk file name encoder using python

Python is really an interesting and user friendly scripting language. It is easy to write codes in python compared to C and some other high level languages..
     It will be much difficult to rename or encode all the file names manually to a particular pattern if the number of files in a folder are too large... For example, If we want to rename all files (for example 1000 files) in a folder to just numbers ,say, 1,2,3 etc with in seconds, this could be easily done using python.
     Below code could be used for the purpose. Also, we could easily rename it back to the original file names using the same script (just double on the rename.py).  A backup file containing the original file names is created in the same folder so that we could rename the numbered files back to its original file names at any time... The renaming to numbers and the reverse could be done just by clicking the same  "rename.py" script copied in the folder containing the files to be bulk renamed and this is very simple and easy process...

Python-Basic Operators


Python language supports following type of operations:
[Arithematic, Comparison, Logical, Assignment, Conditional]

Arithematic operators are:

+ ,  - ,  * ,  / ,  % , ** (exponent) , // (division but digits after decimal in quotient is removed)

Comparison Operators: 
  • ' == ' Checks if the value of two operands are equal or not, if equal then condition becomes true.
  • ' != ' Checks if the value of two operands are equal or not, if not equal then condition becomes true.
  • ' <> ' is similar to ' != '
  • ' > '  checks if the value of left operand is greater than right operand and, if yes then condition become true. Similarly there are comparison operators '<' , '>=', '<=' as in C.

Python - Variable Types


Assigning Values to Variables:

In python, variables are automatically declared when we assign a value to a variable. We use equal sign (=) to assign value to variable. For example:
a = 100                  #integer assignment
name = "linux"       # floating point
num = 244.4412   # string


Multiple Assignment: 

Assigning single value to many variables:
a = b = c = 1
Assigning multiple objects to multiple variables:
a , b , c = 30, 5.54, "hello"
   here  a= 30 , b = 5.54, c = hello

PYTHON SYNTAX


Indentation:
     
         Whitespace is important in Python. Actually, whitespace at the beginning of the line is important. This is called indentation. Leading whitespace (spaces and tabs) at the beginning of the logical line is used to determine the indentation level of the logical line, which in turn is used to determine the grouping of statements. This means that statements which go together must have the same indentation. Each such set of statements is called a block.  Program in a bracketed language would merely become more difficult to read and consumes much time of the programmer and also affects the readability. Indentation solves the above problems of a bracketed languages (like C, C++ etc).

PYTHON




 

PYTHON is an interpreted, interactive, object-oriented programming language.

- When a language is interpreted it means that it is processed at runtime by the interpreter. 
- Interactive means that we can actually sit at a python prompt and interact with the interpreter directly.
- Object-Oriented is a style or technique of programming that encapsulates code within objects.