Posts

Showing posts with the label Arduino Due

Basic Arduino Due oscilloscope

Image
Basic Arduino Due oscilloscope

Implement Timer Interrupt for Arduino Due

Image
The code implement Timer Interrupt for Arduino Due, to toggle LED every second and send the duration in millisecond to PC via Serial port. int led = 13; volatile boolean ledon; volatile unsigned long lasttime; volatile unsigned long now; int FREQ_1Hz = 1; void TC3_Handler(){ TC_GetStatus(TC1, 0); now = millis(); digitalWrite(led, ledon = !ledon); Serial.println(now - lasttime); lasttime = now; } void startTimer(Tc *tc, uint32_t channel, IRQn_Type irq, uint32_t frequency){ //Enable or disable write protect of PMC registers. pmc_set_writeprotect(false); //Enable the specified peripheral clock. pmc_enable_periph_clk((uint32_t)irq); TC_Configure(tc, channel, TC_CMR_WAVE|TC_CMR_WAVSEL_UP_RC|TC_CMR_TCCLKS_TIMER_CLOCK4); uint32_t rc = VARIANT_MCK/128/frequency; TC_SetRA(tc, channel, rc/2); TC_SetRC(tc, channel, rc); TC_Start(tc, channel); tc->TC_CHANNEL[channel].TC_IER = TC_IER_CPCS; tc->TC_CH...

Android code sending command to Arduino Due to turn LED On/Off

Image
It's the coding in Android side to send command to Arduino Due to control LED On/Off. Modify AndroidManifest.xml to add <uses-feature> of "android.hardware.usb.accessory", <intent-filter> of "android.hardware.usb.action.USB_ACCESSORY_ATTACHED", and <meta-data> of resource="@xml/myfilter". <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.androidadkled" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="12" android:targetSdkVersion="17" /> <uses-feature android:name="android.hardware.usb.accessory"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" ...

Read analog input of Arduino Due board

Image
The Arduino Due Board has 12 analog inputs (pins from A0 to A11), each of which can provide 12 bits of resolution (i.e. 4096 different values). By default, the resolution of the readings is set at 10 bits, for compatibility with other Arduino boards. It is possible to change the resolution of the ADC with analogReadResolution(). The Due’s analog inputs pins measure from ground to a maximum value of 3.3V. Applying more then 3.3V on the Due’s pins will damage the SAM3X chip. The analogReference() function is ignored on the Due. Analog input pins on Arduino Due Board Example to read from Analog Input: int analogInputA0 = A0; int varA0; void setup() { Serial.begin(9600); analogReadResolution(12); //set ADC resolution to 12 bits } void loop() { varA0 = analogRead(analogInputA0); //read ADC input Serial.println(varA0, HEX); //print as HEX delay(1000); } Read Analog Input on Arduino Due If the code compiled with error: 'analogReadResolution' was not declared in t...

Control Arduino LED using Python with GUI

Image
This example demonstrate how to control Arduino LED using Python with GUI, using tkinter library. #tkinter for Python 3.x #Tkinter for Python 2.x import serial import time import tkinter def quit(): global tkTop tkTop.destroy() def setCheckButtonText(): if varCheckButton.get(): varLabel.set("LED ON") ser.write(bytes('H', 'UTF-8')) else: varLabel.set("LED OFF") ser.write(bytes('L', 'UTF-8')) ser = serial.Serial('/dev/ttyACM1', 9600) print("Reset Arduino") time.sleep(3) ser.write(bytes('L', 'UTF-8')) tkTop = tkinter.Tk() tkTop.geometry('300x200') varLabel = tkinter.StringVar() tkLabel = tkinter.Label(textvariable=varLabel) tkLabel.pack() varCheckButton = tkinter.IntVar() tkCheckButton = tkinter.Checkbutton( tkTop, text="Control Arduino LED", variable=varCheckButton, command=setCheckButtonText) tkCheckButton.pack(anchor=tki...

Talk with Arduino Due in Python Shell

Image
With pySerial installed, it's easy to communicate with Arduino board in Python Shell. Connect Arduino Due with sketch of former post downloaded. For Python 2.x, enter the commands in Python Shell to turn ON/OFF LED on Arduino Due Board >>> import serial >>> ser = serial.Serial('/dev/ttyACM0', 115200) >>> ser.write('H') >>> ser.write('L') For Python 3.x, the String in write() have to be casted to bytes. >>> import serial >>> ser = serial.Serial('/dev/ttyACM0', 115200) >>> ser.write(bytes('H', 'UTF-8')) >>> ser.write(bytes('L', 'UTF-8')) Related: serial.serialutil.SerialException: could not open port /dev/ttyACM0 Communicate with Arduino in Python programmatically

Read byte from Serial port and set pin

Image
This code run on Arduino Due, read byte from Serial port, and set LED pin HIGH/LOW according. int led = 13; int incomingByte = 0; void setup() { pinMode(led, OUTPUT); //Setup Serial Port with baud rate of 115200 Serial.begin(115200); Serial.println("Press H to turn LED ON"); Serial.println("Press L to turn LED OFF"); } void loop() { if (Serial.available() > 0) { // read the incoming byte: incomingByte = Serial.read(); if(incomingByte == 'H'){ digitalWrite(led, HIGH); Serial.println("LED ON"); }else if(incomingByte == 'L'){ digitalWrite(led, LOW); Serial.println("LED OFF"); }else{ Serial.println("invalid!"); } } }

Hello World ADK: Communication between Arduino Due and Android device

Image
The former post demonstrate half " Pre-Hello World for ADK ". It's further implemented to include communication between Arduino Due and Android Device. In Arduino Due side: it monitor any incoming data from accessory, and send it back. In Android side, it will send out the text when Send button clicked. And display the text received from USB. It implement the function of bi-direction communication between Arduino Due and Android Device. The code in Arduino side is listed here: #include "variant.h" #include <stdio.h> #include <adk.h> // Accessory descriptor. It's how Arduino identifies itself to Android. char applicationName[] = "HelloADK"; // the app on your phone char accessoryName[] = "Arduino Due"; // your Arduino board char companyName[] = "Arduino-er"; // Make up anything you want for these char versionNumber[] = "0.1"; char serialNumber[] = "1"; char url[] = "https://sites.google.com/si...

LCD Demo: Arduino DUE vs Mega 2560

Image
Arduino DUE and Mega 2560 with CTE 3.2" TFT LCD Module with Font IC Demo Up: Arduino DUE w/TFT Shield Down: Mega 2560 w/TFT Shield Running the same demo code with Coldtears electronics 3.2" TFT LCD Module with font and icon IC The first part is demo of the displaying text and icons from the module. The module is a 3.2" LCD module with fonts of 10 sizes and some commonly used icon for application development. The second part is the famous UTFT demo by Henning Karlson. DUE runs at 84Mhz with SPI DMA, mega runs at 16Mhz, As seen due is incredibly faster when loading data from flash and drawing to the LCD

Pre-Hello World for ADK

Image
It's a very simple incomplete "Hello World" for ADK, working on Arduino Due with Android Device. In Arduino Due side, it simple loop to detect if adk isReady(). If adk ready turn on L led, if not turn it off. Also define the URL to download the app if not installed. #include "variant.h" #include <stdio.h> #include <adk.h> // Accessory descriptor. It's how Arduino identifies itself to Android. char applicationName[] = "HelloADK"; // the app on your phone char accessoryName[] = "Arduino Due"; // your Arduino board char companyName[] = "Arduino-er"; // Make up anything you want for these char versionNumber[] = "0.0"; char serialNumber[] = "1"; char url[] = "https://sites.google.com/site/arduinosite/exercise/helloadk/HelloADK_0.0.apk"; USBHost Usb; ADK adk(&Usb, companyName, applicationName, accessoryName,versionNumber,url,serialNumber); // Pin 13 has an LED connected on most Arduino boa...

Test code for ADK on Arduino Due

Image
Arduino 1.5 BETA come with a ADK Terminal Test example to demonstrates USB Host connectivity between an Android phone and an Arduino Due. The ADK for the Arduino Due is a work in progress. For additional information on the Arduino ADK visit http://labs.arduino.cc/ADK/Index . To load the ADK Terminal Test example, select File in Arduino IDE -> Examples -> USBHost -> ADKTerminalTest. Open ADK Terminal Test BUT...it not work in my case! The function Serial.begin(9600) have to be called at the beginning of setup(). After then, it work as expected ( view the video ). From the thread http://arduino.cc/forum/index.php?PHPSESSID=13eedea106bcfa79b016f120f99a8f34&topic=129390.0 ADKTerminalTest /*  ADK Terminal Test  This demonstrates USB Host connectivity between an   Android phone and an Arduino Due.  The ADK for the Arduino Due is a work in pr...

Cabling to connect Arduino Due with Android device

Image
In order to connect Arduino Due with Android device to achieve ADK function , a Micro USB OTG Cable is needed, connected to Native USB Port of Arduino Due. Another normal USB cable is used to connect the USB OTG Cable and Android device. In such connection, the Arduino Due act as host, the Android act as accessory. Connect Arduino Due and Android device with OTG USB Cable

ADK running on Arduino Due

Image
After two day of try and test, I finally get the Arduino Due ADK sample sketch Arduino 1.5 BETA work on Arduino Due Board, link with HTC One X. In coming post, I will explain about: Cabling to connect Arduino Due with Android device Example code for ADK on Arduino Due Related: - My own Hello World ADK: Communication between Arduino Due and Android device

Application Note of Cortex-M3 Embedded Software Development

Image
The Arduino Due is a microcontroller board based on the Atmel SAM3X8E ARM Cortex-M3 CPU (datasheet). It is the first Arduino board based on a 32-bit ARM core microcontroller. The Application Note 179 Cortex™-M3 Embedded Software Development , from ARM Information Center, introduces the main features of the ARM Cortex™-M3 processor and describes different aspects of developing software for it. It also covers the migration of existing ARM projects to the Cortex-M3 platform. PDF version available at the bottom of the page. Application Note of Cortex-M3 Embedded Software Development Table of Contents 1. The Cortex™-M3 1.1. Nested Vectored Interrupt Controller (NVIC) 1.2. Memory Protection Unit (MPU) 1.3. Debug Access Port (DAP) 1.4. Memory map 2. Developing software for Cortex-M3 2.1. Exception handling 2.2. Memory Protection Unit (MPU) 2.3. Stack and heap configuration 2.4. Instruction set support 2.5. Bit-banding 2.6. Execution Modes 2.7. Supervisor Calls (SVC) 2.8. System Timer (SysTick...

Missing component in Arduino Due

Image
It seem that a component is missed on my new buy Arduino Due Board R3! Anybody can tell me what's it? it is necessary? Missing component in Arduino Due

Arduino Due with ARM Cortex-M3 explained by Massimo Banzi, Co-founder of Arduino

Image

Arduino Due Board

Image
Arduino Due Board AT91SAM3X8E ARM 32-bit Microcontroller @ 84MHz Operating Voltage: 3.3V 54 digital I/O pins, 12 analog inputs, 2 DAC (analog output) Flash Memory: 512 KB all available for the user applications SRAM: 96 KB (two banks: 64KB and 32KB) The Arduino Due is the newcomer microcontroller board in the Arduino boards family. It's the first board based on a 32 bit ARM core processor, the Atmel SAM3X8E ARM Cortex-M3 MCU, that improve all the standard Arduino functionalities and add more new features. It offer 54 digital input/output pins (of which 12 can be used as PWM outputs, with selectable resolution), 12 analog inputs with 12 bit of resolution, 4 UARTs (hardware serial ports), and two DAC outputs (digital to analog converter), 84 MHz crystal oscillator, two USB connections, a power jack, an ICSP header, a JTAG header, and a reset button. The maximum voltage that the I/O pins can provide or tolerate is 3.3V. Providing higher voltages, like 5V to an input pin could damage t...