Feb 14, 2014 1 Comments in Getting Start, Learning, Mega 2560, User Manuals by
Cosino Mega 2560 – User Manual

This product can be bought at our shop as:

Overview

The system supports any Arduino Mega 2560 shields which makes it suitable for extending all applications based on Mega 2560 and that need additional connectivity such as 3D printers, monitoring and/or controlling systems.

Prerequisite

You need a Cosino core module to be plugged into Mega 2560 extension and a preformatted microSD in order to have a running system. Also, if you need system’s console, you must connect a type B-micro USB cable to the serial console connector.

Top view

Here an useful image where all ports/connectors are explicated.

Cosino Mega 2560 connectors

Booting the system

Once Cosino core module is plugged into this extension and the preformatted microSD is inserted into its slot, if you need a system console, you must connect a type B-micro USB cable to the serial console port.

warning Refer on this tutorial about how to get access to the serial console.

If everything works well you should see the login message:

remember that the root’s password in the preformatted microSD is simply root.

Surfing the net

Ethernet

After plugging the ethernet cable into Cosino’s ethernet port you should see on the serial console the following message:

In the preformatted microSD is defined a static IP address for device eth0:

You can change it to suite your needs by modifying file /etc/network/interfaces at eth0‘s fields in order to fit your LAN configuration:

or just use command dhclient in order to get network configuration from your DHCP server:

Wireless

If your system has an on board WiFi module you should see the following messages at boot time:

Then you can take a look at this tutorial in order to know how to setup a WiFi device.

However if you need to add the WiFi support into your Debian you can do it by exploding the files:

into the microSD as follow:

Then reboot the system.

The expansion connectors A & B

Most Cosino’s peripherals ports have their own connectors but by using the expansion connectors A & B you can add more hardware to your Cosino Mega 2560 board! Here a complete list of connectors pinout:

Signal B/J21 Signal
Description /Alternate Reference I/O     I/O Reference Description /Alternate
Usb Host or Device A – HHSDMA USB 1 2 USB HHSDPA Usb Host or Device A +
  +5V Power 3 4 Power +5V  
  +3,3V Power 5 6 Power +3,3V  
  PA28 gpio 7 8 gpio PA27  
  PA26 gpio 9 10 gpio PA29  
  PA25 gpio 11 12 gpio PA24  
  PB17 gpio 13 14 gpio PB15  
SPI_SPCK PA23 gpio 15 16 gpio PB18 IRQ | ADTRG
  PD18 gpio 17 18 gpio PA22 SPI1 MOSI
Uart RX1 PA6 gpio 19 20 gpio PA21 SPI1 MISO
I2C SDA PA30 gpio 21 22 gpio PB16  
  PA14 gpio 23 24 gpio PA5 Uart TX1
I2C SCL PA31 gpio 25 26   —– Not Used
PWM0 PC18 gpio 27 28 gpio PC20 PWM2
PWM1 PC19 gpio 29 30 gpio PC21 PWM3
Not Used —–   31 32   —– Not Used
  GND Power 33 34 Power GND  
  PD19 gpio 35 36 gpio PD20  
               
               
Signal A/J13 Signal
Description /Alternate Reference I/O     I/O Reference Description /Alternate
  +5V Power 1 2   —–  
Usb Host C – HHSDMC USB 3 4   —– Not Used
Usb Host C + HHSDPC USB 5 6   —–  
  GND Power 7 8   —– Not Used
Not Used —–   9 10   —–  

warning Note: all GPIOs are CMOS 3.3V

The UART port

The UART port (RS-232 compatible) is attached to device /dev/ttyS2 and it can be accessed as a normal serial port.

Signal J21
Description
TX1 24
RX1 19

warning Note: this port has not the RS232 electrical levels! You need an adapter like this one if you wish connect this serial port to a standard RS-232 port!

The RS485 port

The RS485 port is attached to device /dev/ttyS1 and it can be accessed as a normal serial port.

Signal J19
Description  
 RS485- 1
 RS485+ 2
 ref. RS485 3

The USB ports

Mega 2560 extension provides a ready to use USB (host) type A port but there are two other USB ports on the expansion connectors A & B!

On the expansion connector A you can find a supplemental USB host port where you can connect an USB device directly or through a USB type A port.

Signal J13
Description  
 VCC 1
 USB- 3
 USB+ 5
GND 7

On the expansion connector B you can find a supplemental USB device port where you can connect an USB host directly or through a USB type B port.

Signal J19
Description  
 USB- 1
 USB+ 2
 GND 33

The I2C port

An I2C port is available on the expansion connector B:

Signal J21
Description
Clock I2C SCL
Data I2C SDA

Then you can easily test an I2C device connection by using the i2c-dev module as follow:

a new /dev/i2c-0 file will be created that can be used to get access to the I2C bus.

The SPI port

An SPI port is available on the expansion connector B:

Signal J21
Description
Clock SPI CLK
MOSI SPI MOSI
MISO SPI MISO
CS0 PA14

As default the SPI port has enabled 1 chip-select only (at PA14 pin) but it can manage up to 4 chip selects by modifying the DTS file arch/arm/boot/dts/at91-cosino_mega2560.dts (and even more than 4 CS by modifying the driver itself!).

Here the relevant code in the DTS file:

See this tutorial in order to recompile the kernel code.

Then you can easily test a SPI device connection by using the spidev module as follow:

a new /dev/spidev32766.0 file will be created that can be used to get access to the SPI bus (see here for a simple tutorial).

The GPIOs

On the expansion connector B you can find some GPIOs pins as reported below:

System GPIO #ID J21
14 PA14
24 PA24
25 PA25
26 PA26
27 PA27
28 PA28
29 PA29
47 PB15
46 PB16
49 PB17
50 PB18
114 PD18
115 PD19
116 PD20

Each GPIO label is mapped into the Cosino’s system by using its GPIO ID number. So, for instance, GPIO PA27 is referred as GPIO27.

If you wish getting access to GPIO PA27 you must export it by using command:

so the system will create a new directory named /sys/class/gpio/pioA27 where you can control the GPIO:

File direction controls the GPIOs direction mode (input/output) while into the file value you can read/write the GPIO status. For instance, if you wish set the GPIO as an output with an high output value you should do:

The PWMs

On the expansion connector B you can find 4 PWMs channels as reported below:

PWM #ID J21
0 PWM0
1 PWM1
2 PWM2
3 PWM3

Each PWM label is mapped into the Cosino’s system by using its PWM ID number.

If you wish getting access to PWM0 you must export it by using command:

so the system will create a new directory named /sys/class/pwm/pwmchip0/pwm0 where you can control the PWM parameters:

File period holds the PWM square wave period in nanoseconds while the file duty_cycle holds the duty cycle in nanoseconds. File polarity set the wave polarity end the file enable just enable the PWM output.

As example, if you wish to generate a square wave with period of 100uS and duty cycle 50uS the commands are:

 Accessing to Mega 2560’s CPU

The core of Mega 2560 extension is the Arduino-Compatible CPU. If you already have a project running on an Arduino Mega 2560 you can run it on the Mega 2560 extension without any modification! You can use all your shields too!

warning Note: according to Arduino hardware licensing we inform that all schematics are published into the Press area.

In order to send your code to the Mega 2560 CPU you must use the avrdude program.

Currently you cannot use default avrdude Debian package since it needs a dedicated patch in order to work with Cosino (we hope this patch will be accept in avrdude main stream soon); however we provide a ready-to-use package on our GitHub site (see above how to clone it so copy avrdude files into your Cosino):

Now to install them on Cosino use the command:

Good, avrdude is now ready! We can use a simple script to help us in managing Mega 2560 code upload; we named it mega2560.sh and you can find it on the just cloned repository. So let’s copy it on your Cosino:

and then use the command below to upload the code into the file firmware.hex:

Then you can use the following command to hard reset the Mega 2560’s CPU:

Just for testing you can use provided firmware into file blink.hex; copy the file into your Cosino as usual:

and then upload it into Mega 2560 CPU:

Now we simply reset the Mega 2560 CPU and then we take a look at data arriving from the serial port /dev/ttyS3 (the port connected with the Mega 2560 CPU):

Great! Firmware uploading is ok and now you should see a blinking led near the external power supply connector.

Visual pinout

In the following figure you can see a visual pinout of both expansion connectors A & B and Arduino Mega 2560 ones (please note that board has been splitted for better readability).

mega2560 pins layout

warning Note: on Connectors A & B all GPIOs are CMOS 3.3V while on Mega 2560 ones GPIOs are CMOS 5V!

FAQ

First steps (turning on the system, connecting the serial console, etc.)

1) I powered my Cosino Mega 2560 but I cannot see any message from the serial console! What can I do?

First of all be sure that Cosino (the CPU module) is well inserted into the extension’s connectors.

Then, if you are not using an external power supply, be sure that the USB serial console cable is directly connected with your PC and not to an USB HUB! In fact most USB HUBs doesn’t provide the 500mA per port as stated by USB specifications.

When you power up the system you should see the board’s leds turned on (or flashing) and the PC should see a new connected USB device (see here for a complete guide).

If you are using a GNU/Linux host PC and still your minicom doesn’t show anything to you try to remove any inserted microSD, close minicom and try using the following commands:

warning Note: please, change device /dev/ttyUSB1 in order to fit your system configuration

If everything works well you should see the RomBOOT message as cat command output.

2) I connected the USB cable to get access to the serial console but my host PC Linux based do not recognize it so I have no /dev/ttyUSB0 device to connect to! What’s wrong?

Try using lsusb command to get a list of the USB devices connected to your system:

The first line, where you can read ID 0403:6015 Future Technology Devices International, Ltd, you have the Cosino’s serial console! If you have no /dev/ttyUSBx devices maybe your kernel is a bit old… try loading ftdi_sio driver with the command:

3) I connected the USB cable to get access to the serial console but my host PC Windows based do not recognize it so I have no COM9 device to connect to! What’s wrong?

This usually happens when your system have no USB serial drivers installed, then you should visit this site and install them.

Mega 2560 CPUs

1) I cannot load my HEX file into Mega 2560 CPU by using the mega2560.sh tool:

Any ideas?

You cannot use standard avrdude program (yet) to get access to the Mega 2560 CPU as described here!

Debian

1) I’m trying to install a package but I got:

So that file seems to have moved/renamed/notproperlylinked/whatever!

Debian repositories are kept updated so you have to reflect it into your system. Just use the command:

to fix them.

2) I just updated the kernel from the Github repository and now the WiFi is not functional anymore! How I can fix this issue?

Just try using the command:

and the reboot the system.

If this fails try to reinstall the WiFi’s driver as described above in the Wireless section.

Facebooktwitterlinkedin
Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

− 4 = 3