Posts with «gpio» label

Odyssey Is A x86 Computer Packing An Arduino Along For The Trip

We love the simplicity of Arduino for focused tasks, we love how Raspberry Pi GPIO pins open a doorway to a wide world of peripherals, and we love the software ecosystem of Intel’s x86 instruction set. It’s great that some products manage to combine all of them together into a single compact package, and we welcome the recent addition of Seeed Studio’s Odyssey X86J4105.

[Ars Technica] recently looked one over and found it impressive from the perspective of a small networked computer, but they didn’t dig too deeply into the maker-friendly side of the product. We can look at the product documentation to see some interesting details. This board is larger than a Raspberry Pi, but its GPIO pins were laid out in exactly the same order as that on a Pi. Some HATs could plug right in, eliminating all the electrical integration leaving just the software issue of ARM vs x86. Tasks that are not suitable for CPU-controlled GPIO (such as generating reliable PWM) can be offloaded to an on-board Arduino-compatible microcontroller. It is built around the SAMD21 chip, similar to the Arduino MKR and Arduino Zero but the pinout does not appear to match any of the popular Arduino form factors.

The Odyssey is not the first x86 single board computer (SBC) to have GPIO pins and an onboard Arduino assistant. LattePanda for example has been executing that game plan (minus the Raspberry Pi pin layout) for the past few years. We’ve followed them since their Kickstarter origins and we’ve featured creative uses here and there. LattePanda’s current offerings are built around Intel CPUs ranging from Atom to Core m3. The Odyssey’s Celeron is roughly in the middle of that range, and the SAMD21 is more capable than the ATmega32U4 (Arduino Leonardo) on board a LattePanda. We always love seeing more options in a market for us to find the right tradeoff to match a given project, and we look forward to the epic journeys yet to come.

Arduino Gets a Command Line Interface

When using an Arduino, at least once you’ve made it past blinking LEDs, you might start making use of the serial connection to send and receive information from the microcontroller. Communicating with the board while it’s interacting with its environment is a crucial way to get information in real-time. Usually, that’s as far as it goes, but [Pieter] wanted to take it a step farther than that with his command line interpreter (CLI) for the Arduino.

The CLI allows the user to run Unix-like commands directly on the Arduino. This means control of GPIO and the rest of the features of the microcontroller via command line. The CLI communicates between the microcontroller and the ANSI/VT100 terminal emulator of your choosing on your computer, enabling a wealth of new methods of interacting with an Arduino.

The CLI requires a hex file to be loaded onto the Arduino that you can find at a separate site, also maintained by [Pieter]. Once that’s running, you can get all of that sweet command line goodness out of your Arduino. [Pieter] also has some examples on his project page, as well as the complete how-to to get this all set up and running. There’s a lot going on in the command line world, in Linux as well as windows. So there’s plenty to explore there as well.

Hack a Day 11 Nov 03:00
arduino  cli  command line  gpio  i2c  microcontrollers  serial  shell  unix  uno  

Save Some Steps with this Arduino Rapid Design Board

We’re all familiar with the wide variety of Arduino development boards available these days, and we see project after project wired up on a Nano or an Uno. Not that there’s anything wrong with that, of course, but there comes a point where some hobbyists want to move beyond plugging wires into header sockets and build the microcontroller right into their project. That’s when one generally learns that development boards do a lot more than break the microcontroller lines out to headers, and that rolling your own design means including all that supporting circuitry.

To make that transition easier, [Sean Hodgins] has come up with a simple Arduino-compatible module that can be soldered right to a PCB. Dubbed the “HCC Mod” for the plated half-circle castellations that allows for easy soldering, the module is based on the Atmel SAMD21 microcontroller. With 16 GPIO lines, six ADCs, an onboard 3.3 V regulator, and a reset button, the module has everything needed to get started — just design a PCB with the right pad layout, solder it on, and surround it with your circuitry. Programming is done in the familiar Arduino IDE so you can get up and running quickly. [Sean] has a Kickstarter going for the modules, but he’s also releasing it as open source so you’re free to solder up your own like he does in the video below.

It’s certainly not the first dev module that can be directly soldered to a PCB, but we like the design and can see how it would simplify designs. [Sean] as shown us a lot of builds before, like this army of neural net robots, so he’ll no doubt put these modules to good use.

Adding I/O to the Rasberry Pi Models A & B

The Raspberry Pi has been the basis for many cool projects. Even so, Models A and B have been criticized for having only a handful of GPIO pins available. Sure, the new Model B+ has a 40-pin GPIO header but what if you want to use your old RaspPi with a bunch of in and outputs? [Steve] is one of those guys and has done something about it by creating a pretty neat solution he calls the PiMagic. It’s a Pi Plate that has an on board ATMEGA328 running an Arduino bootloader. The RaspPi and the Arduino communicate via UART as [Steve] felt it was a bit simpler than going the SPI or I2C route.

The RaspPi GPIO’s run on 3.3v and the ATMEGA328’s like 5v. To solve this, the PiMagic has a Level Shifter that keeps the I/O of the two boards happy. Older Pi’s had a problem burning out PCB traces when supplying too much current on the 5v supply line. [Steve] threw in a fuse that will burn out before the Pi does to ensure that no Pi’s were harmed in the making of this project.

Now that a bunch of I/O are available, how do you physically access them? Well, the PiMagic has female headers in the typical Arduino layout. This way any Arduino Shield will plug right in. [Steve] made all his source files available for those who want to make one themselves. Find an assembly video after the break.


Filed under: Raspberry Pi
Hack a Day 09 Sep 09:01

Tutorial – pcDuino GPIO with Arduino IDE

Introduction

In this tutorial we’ll explain how to use the GPIO pins of the Arduino implementation in the pcDuino v2 and v3. As the v3 is now available you can use it as well, and it’s interchangeable with the v2. Although the pcDuino v2 is Arduino-compatible, there are a few differences that you need to be aware of – in order to make your projects a success and also to avoid any costly mistakes.

This tutorial builds on the knowledge from the initial review, so if pcDuino v2 is new to you please review this article before moving on. In this instalment we’ll run through the following:

  • ADC (analogue to digital)
  • Digital input and outputs
  • PWM (pulse-width modulation)
  • I2C bus
  • SPI bus

Using ADC pins

Just like an Arduino Uno or compatible, the pcDuino v2 has six ADC pins, in the expected locations:

Using the pcDuino v2’s ADC pins is quite straight forward, however you just need to remember a few things about the hardware – that the maximum input voltage on A0 and A1 is 2V – and 3.3V for A2~A5.

Although there is an AREF pin on the board, this function isn’t supported at the time of writing. From the software perspective A0 and A1’s values have a 6-bit resolution and can fall between 0 and 63 (0~2V), otherwise the others have a 12-bit resolution and thus return values between 0 and 4095 (0~3.3V). Using the ADC pins is simple, and demonstrated in the following sketch:

// pcDuino v2 ADC demonstration

#include <core.h> // for pcDuino

int a0, a1, a2, a3, a4, a5;

void setup() 
{
}

void loop() 
{
  // read all the ADCs
  a0 = analogRead(0);
  a1 = analogRead(1);
  a2 = analogRead(2);
  a3 = analogRead(3);
  a4 = analogRead(4);
  a5 = analogRead(5);
  // display ADC values to console
  printf(A0, A1,   A2,   A3,   A4,   A5\n);
  printf(%d  %d  %d  %d  %d  %d\n, a0, a1, a2, a3, a4, a5);
  printf(n);
  delay(1000);
}

… which results with the following in the console:

Digital outputs

The pcDuino v2’s implementation of digital outputs aren’t anything out of the ordinary – except that you are limited to a maximum voltage of 3.3V instead of the usual 5V. Furthermore you can only source 4mA from each pin. However if you have some 5V-only shields that you must use with your pcDuino v2 – there is a Voltage Translation board that can be used to solve the problem:

However using 3.3V for new designs shouldn’t be an issue – new sensors, ICs and so on should be 3.3V-compatible. And with the pcDuino v2 you get an extra four digital I/O pins, located next to the SPI grouping as shown below:

These are simply addressed as D14~D17. Now back for a quick demonstration with the typical LEDs. As the current sourced from each GPIO pin cannot exceed 4mA, you need to use a resistor to keep things under control. Using the LED wizard, by entering a 3.3V supply, 2.1V forward voltage for our LEDs and a 4mA current – the resistor value to use is 330Ω.

If you’re having a lazy attack and use 560Ω, the current will be around 2.5mA with acceptable results. We’ve done just that with the following demonstration sketch:

// pcDuino v2 digital output demonstration

#include <core.h> // for pcDuino

void setup() 
{
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);  
  digitalWrite(4, LOW);  
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);  
}

void loop() 
{
  for (int i = 4; i < 8; i++)
  {
    digitalWrite(i, HIGH);
    delay(250);
    digitalWrite(i, LOW);
  }
}

… and the results in this video.

Digital inputs

When using the digital pins as inputs, just treat them as normal except they have a maximum input voltage of 3.3V for HIGH. Again – just keep thinking “3.3V”.

Using the I2C data bus

The I2C bus (or “two wire interface”) is a common serial data bus used for interfacing all manner of devices with a microcontroller. You can find a background on the I2C bus and Arduino tutorial here. Just like an Arduino Uno R3, the I2C bus pins are both A4 and A5 (for SCL and SDA) and can also be found up near D13, for example.

The limitations for the pcDuino v2’s version of I2C bus are few – the maximum speed is 200 kHz, it only uses 7-bit addresses and you can’t use the pcDuino in slave mode. However there are 2.2kΩ pullup resistors which can save using them with external circuitry.

We demonstrate the I2C bus by writing data to and reading it from a Microchip 24LC256 EEPROM (which is handy in itself as there isn’t any EEPROM function on the pcDuino v2). This is demonstrated with an Arduino Uno in part two of our I2C tutorials.

Connection is very easy – pins 1 to 4 of the EEPROM are connected to GND, pin 5 to SDA, pin 6 to SCL, pin 7 to GND and pin 8 to 3.3V. Finally a 0.1uF capacitor is placed across 3.3V and GND.

The sketch to read and write values to the EEPROM is simple, and apart from the #include <core.h> for the pcDuino all the other functions operate as normal.

// pcDuino I2C demonstration

#include <core.h> // for pcDuino
#include <Wire.h>   for I2C
#define chip1 0x50  device bus address for EEPROM

// always have your values in variables
unsigned int pointer = 69;  // we need this to be unsigned, as you may have an address  32767
byte d=0;  // example variable to handle data going in and out of EERPROMS

void setup()
{
  Wire.begin();  // wake up, I2C!
}

void writeData(int device, unsigned int add, byte data) 
// writes a byte of data 'data' to the chip at I2C address 'device', in memory location 'add'
{
  Wire.beginTransmission(device);
  Wire.write((int)(add  8)); // left-part of pointer address
  Wire.write((int)(add & 0xFF)); // and the right
  Wire.write(data);
  Wire.endTransmission();
  delay(10);
}

byte readData(int device, unsigned int add) 
// reads a byte of data from memory location 'add' in chip at I2C address 'device' 
{
  byte result;  // returned value
  Wire.beginTransmission(device);  // these three lines set the pointer position in the EEPROM
  Wire.write((int)(add  8));  // left-part of pointer address
  Wire.write((int)(add & 0xFF)); // and the right
  Wire.endTransmission();
  Wire.requestFrom(device,1); // now get the byte of data...
  result = Wire.read();
  return result;  // and return it as a result of the function readData
}

void loop()
{
  printf(Writing data...\n);
  for (int a=0; a10; a++)
  {
    writeData(chip1,a,a);
  }
  printf(Reading data...\n);
  for (int a=0; a10; a++)
  {
    d=readData(chip1,a);    
    printf(Pointer %d holds %d.\n,a,d);
  }
}

… which results with the following output in the console:

As you now know, using I2C isn’t hard at all. A lot of beginners shy away from it – or run screaming for the nearest library for their part. You don’t need libraries – spend a little time now learning about I2C and you’re set for life.

Using the SPI data bus

Again we have some SPI tutorials for Arduino, so check them out first if the concept is new to you. Writing to an SPI device with the pcDuino v2 isn’t tricky at all, you have the 3.3V hardware limitation and the SPI pins are in the same location (D10~D13) or in a separate group on the board:

Furthermore the maximum SPI speed is 12 MHz and the pcDuino v2’s  implementation of SPI can only work as a master. However in the sketch there are a few differences to note. To demonstrate this we’ll control a Microchip MCP4162 digital rheostat via SPI to control the brightness of an LED. Here is the circuit:

And now for the sketch. Take note of the fourth line in void setup() –  this is used to set the SPI bus speed to 12 MHz. You can also reduce the speed with other multipliers such as 32, 64 and 128 to slow it down even further. The other point to note is the use of SPI.transfer(). With the pcDuino v2 there are two parameters – the first is the data to send to the SPI device, and the second is either

SPI_CONTINUE

if there is another byte of data following immediately, or

SPI_LAST

if that is the last byte for that immediate transfer. You can see this use of the paramters within the function setValue() in the demonstration sketch below.

// pcDuino SPI demonstration

#include <core.h>  // for pcDuino
#include <SPI.h>
int ss = 10;
int del = 1000;

void setup()
{
  SPI.begin();
  SPI.setDataMode(SPI_MODE3);
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV16);
  pinMode(ss, OUTPUT);
  digitalWrite(ss, HIGH);
}

void setValue(int value)
{
  digitalWrite(ss, LOW);
  SPI.transfer(0, SPI_CONTINUE);
  SPI.transfer(value, SPI_LAST);
  digitalWrite(ss, HIGH);
}

void loop()
{
  setValue(255);
  delay(del);
  setValue(223);
  delay(del);
  setValue(191);
  delay(del);
  setValue(159);
  delay(del);
  setValue(127);
  delay(del);
  setValue(95);
  delay(del);
  setValue(63);
  delay(del);
  setValue(31);
  delay(del);
  setValue(0);
  delay(del);
}

When using the SPI bus, relevant data will appear in the console, for example:

And finally the demonstration video to show you it really works – you can see the output voltage from the rheostat and the matching LED brightness.

Receiving data from the SPI bus is equally as simple, however at the time of writing we don’t have an SPI device to demonstrate this, so please refer the SPI part of the pcDuino guide. Finally, you can’t use PWM on D10 or D11 when using the SPI bus in your sketch.

Pulse-width modulation

You can simulate analogue output using PWM with a pcDuino v2 – however there are two types of PWM pins available. The first is found on digital pins D3, D9, D10 and D11 – they are simulated PWM – and have a low range of zero to twenty at 5 Hz. There are two hardware PWM pins – D5 and D6, which  run at 520Hz and have the full range of 0~255 available in analogWrite(). Once again – they output 3.3V. Furthermore, you can’t use pinMode() functions or the SPI bus if using D10 and/or D11 for PWM.

Conclusion

Now you should have an understanding of the features and limitations of using GPIO pins with your pcDuino v2 Arduino sketches. And finally a plug for my own store – tronixlabs.com – offering a growing range and Australia’s best value for supported hobbyist electronics from adafruit, DFRobot, Freetronics, Seeed Studio and much more.

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our forum – dedicated to the projects and related items on this website.

The post Tutorial – pcDuino GPIO with Arduino IDE appeared first on tronixstuff.

Tronixstuff 29 Jan 04:12
adc  arduino  gpio  i2c  input  output  pcduino  pwm  review  spi  tronixlabs  tronixstuff  tutorial