Wednesday, April 18, 2018

Atmel Studio 7 Set-up for Arduino UNO Programming

Abstract: Arduino Uno is one of the most used boards by beginners to learn embedded systems. The easiest way to program Arduino Uno is to write code in the sketch programming language using the default Arduino software (Arduino IDE). The Arduino IDE interface is very simple and writing programs in sketch is very easy. This is both an advantage and a weakness of programming with the Arduino IDE, where someone who wants to learn more about the microcontroller system will experience difficulties because they cannot see how the processor works more transparently. There are several alternatives to the Arduino IDE for programming in assembly and C / C ++, one of which is Atmel Studio 7.In this paper, I will explain how to set the environment for Arduino Uno programming using Atmel Studio 7 software.

Abstrak: Arduino Uno merupakan salah satu board yang paling banyak digunakan oleh pemula untuk mempelajari sistem embedded. Cara termudah untuk memprogram Arduino Uno adalah dengan menulis code dalam bahasa pemrograman sketch menggunakan software bawaan dari Arduino (Arduino IDE). Interface Arduino IDE sangat sederhana dan menulis program dalam sketch-pun sangat mudah. Hal ini merupakan kelebihan sekaligus kelemahan pemrograman dengan Arduino IDE, dimana seseorang yang ingin mempelajari sistem mikrokontroller lebih mendalam, akan mengalami kesulitan karena tidak dapat melihat cara kerja prosesor secara lebih transparan. Ada beberapa alternatif dari Arduino IDE untuk pemrograman dalam assembly maupun C/C++, salah satunya adalah Atmel Studio 7. Pada tulisan ini, saya akan menjelaskan cara setting environment untuk pemrograman Arduino Uno dengan menggunakan software Atmel Studio 7.

Sunday, April 15, 2018

Arduino UNO /AVR 328P Serial USART Transmission in Assembly




;
; Serial USART.asm
;
; Created: 4/15/2018 9:24:49 PM
;

.equ    UBRRNX0=103    ; 9600bps
.equ    UBRRNX1=207

// start code
start:
    rcall    USART_Init
    ; write your code here
    ldi        r16,0x24
    rcall USART_Transmit   

end:
    rjmp    end

; end of your code
; this is my part
;----------
USART_Init:
    push r16
    push r17
       
    ldi r16, low(UBRRNX0)            ; Set baud rate to UBRR0
    ldi r17, high(UBRRNX0)
    sts UBRR0H, r17
    sts UBRR0L, r16
       
    ldi r16, (1
<<RXEN0)|(1<<TXEN0)    ; Enable receiver and transmitter
    sts UCSR0B,r16
       
    ldi r16, (1
<<USBS0)|(3<<UCSZ00)    ; Set frame format: 8data, 2stop bit
    sts UCSR0C,r16
    pop r17
    pop r16
    ret

USART_Transmit:
    push r17
    lds r17, UCSR0A                    ; Wait for empty transmit buffer
    sbrs r17, UDRE0
    rjmp USART_Transmit
       
    sts UDR0,r16                    ; Put data (r16) into buffer, sends the data
    pop r17
    ret

Sunday, April 8, 2018

Arduino UNO Blinking with Timer on Assembly


.equ    DELOOP=10
.MACRO  CPL                    ; Macro to complemen pin
    sbi    0x1E,    @1            ; use this register to xor the pin
    in    r17,    0x1E
    in    r16,    @0        
    eor r16,    r17        
    out @0,        r16
.ENDMACRO

.ORG 0x0000                    ; The beginning of everything
    rjmp START                ; the reset vector: jump to "main"

.ORG 0x0020                    ; interrupt vector: timer0 overflow
    rjmp timer0_overflow    ; jump to interrupt handler

.ORG 0x0034                    ; memory address start of "main function"
START:
    ldi r22,    DELOOP                ; initial value for timer looping

    ldi r16,    0xFF         
    out DDRB,    r16            ; set Port B as output

    ldi r16,    0x0000   
    out TCCR0A, r16            ; timer 0 run in normal mode
    ldi r16,    0x0001   
    sts TIMSK0,    r16
    ldi r16,    0b00000101        ; Set r16 with prescaler 1024 value
    out TCCR0B, r16            ; Set the TCCROB to 1024
    SEI                        ; enable global interrupt

LOOP:
    rjmp LOOP            ; jump to loop

timer0_overflow:
    dec        r22
    breq    toggle
    reti

toggle:                    ; the subroutine:
    ldi        r22, DELOOP
    CPL        PortB, 5            ; toggle the LED
    reti





Load programs to an Arduino UNO from Atmel Studio 7

Many tools can be used, but I like mostly Arduino Sketch Uploader



ArduinoSketchUploader
arduino-uno-from-atmel-studio-7
other
other

Saturday, April 7, 2018

Reset MySQL Root Password

-----
Basic step to reset mysqld password just follow these instructions :
  • Stop the mysql demon process
    •    sudo /etc/init.d/mysql stop
  • Start the mysqld demon process using the --skip-grant-tables option
    •    sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
      or
         sudo mysqld_safe --skip-grant-tables &
       
  • start the mysql client process using this command
    •    mysql -u root
  • from the mysql prompt execute this command to be able to change any password
    •    FLUSH PRIVILEGES;
  • Then reset/update your password
    •    SET PASSWORD FOR root@'localhost' = PASSWORD('password');
  • If you have a mysql root account that can connect from everywhere, you should also do:
    •    UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
  • Alternate Method:
    •    USE mysql
         UPDATE user SET Password = PASSWORD('newpwd')
         WHERE Host = 'localhost' AND User = 'root';
  • And if you have a root account that can access from everywhere:
    •    USE mysql
         UPDATE user SET Password = PASSWORD('newpwd')
         WHERE Host = '%' AND User = 'root';
For either method, once have received a message indicating a successful query (one or more rows affected), flush privileges:
   FLUSH PRIVILEGES;

Then stop the mysqld process and relaunch it
   sudo /etc/init.d/mysql stop
   sudo /etc/init.d/mysql start
 

-- Alternative method for different source
 
1. Run bash commands
 

# 1. first, run these bash commands
sudo /etc/init.d/mysql stop # stop mysql service
sudo mysqld_safe --skip-grant-tables & # start mysql without password
# enter -> go
mysql -uroot # connect to mysql

2. Run mysql commands

use mysql; # use mysql table
update user set authentication_string=PASSWORD("") where User='root'; # update password to nothing
update user set plugin="mysql_native_password" where User='root'; # set password resolving to default mechanism for root user

flush privileges;
quit;

3. Run more bash commands

sudo /etc/init.d/mysql stop 
sudo /etc/init.d/mysql start # reset mysql 
mysql -u root -p root # try login to database
 
 

-- If you find following error

2017-02-10T17:05:44.870970Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-02-10T17:05:44.872874Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-02-10T17:05:44.874547Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists. 
 
Do this 
$ mkdir -p /var/run/mysqld
$ chown mysql:mysql /var/run/mysqld

To reset 
Mysqld_safe 
Solving Error 
 

Thursday, April 5, 2018

Setup PHP on Ubuntu

Please check these links

LAMP
LAMP how to

To install PHP 7 on Ubuntu 
sudo apt-get -y update
sudo add-apt-repository ppa:ondrej/php
sudo apt-get -y update
sudo apt-get install -y php7.0 libapache2-mod-php7.0 php7.0 php7.0-common php7.0-gd php7.0-mysql php7.0-mcrypt php7.0-curl php7.0-intl php7.0-xsl php7.0-mbstring php7.0-zip php7.0-bcmath php7.0-iconv php7.0-soap
 

 
PHP install guide

to Upgrade to PHP7
PHP7

 If an "PHP ERROR: Module php7.0 does not exist" occur

PHP ERROR

to install PHPmyAdmin

sudo apt-get install phpmyadmin
phpMyAdmin

Tuesday, April 3, 2018

Adaptive Runge Kutta to Solve ODE

This is a paperwork of my student. You can refer to this.

Download paper

Sunday, April 1, 2018

Blinking Arduino Uno with Assembly


.ORG 0x0000            ; the next instruction has to be written to
                       ; address 0x0000
rjmp START             ; the reset vector: jump to "main"
START:
    ldi r16, low(RAMEND)   ; set up the stack
    out SPL, r16
    ldi r16, high(RAMEND)
    out SPH, r16
    ldi r16, 0xFF          ; load register 16 with 0xFF (all bits 1)
    out DDRB, r16          ; write the value in r16 (0xFF) to Data
                       ; Direction Register B
LOOP:
    sbi PortB, 5         ; switch off the LED
    rcall delay_05       ; wait for half a second
    cbi PortB, 5         ; switch it on
    rcall delay_05       ; wait for half a secon
    rjmp LOOP            ; jump to loop

DELAY_05:              ; the subroutine:
    ldi r16, 31          ; load r16 with 31

OUTER_LOOP:            ; outer loop label
    ldi r24, low(1021)   ; load registers r24:r25 with 1021, our new
                        ; init value
    ldi r25, high(1021)  ; the loop label
DELAY_LOOP:            ; "add immediate to word": r24:r25 are
                       ; incremented
    adiw r24, 1          ; if no overflow ("branch if not equal"), go
                        ; back to "delay_loop"
    brne DELAY_LOOP
    dec r16              ; decrement r16
    brne OUTER_LOOP      ; and loop if outer loop not finished
    ret                  ; return from subroutine


Ref:
ref1
ref2