Can’t Get I2C to Work on an Arduino Nano? (Pinout Diagrams)

Maybe it is because many of the pinout diagrams for the Nano have SCL and SDA on the wrong pins.

You probably think (as I did and as the guys laying out the pinout diagrams) that these would be on digital pins, but they are not. They are on analog pins.

SDA              Pin A4
SCL              Pin A5

Once you wire it up correctly, this arduino I2C scanner will let you know you have proper connectivity and the address for the device:

http://playground.arduino.cc/Main/I2cScanner

Jump to Pinout for:


Here is a correct Nano pin out diagram:


And while I’m at it, here is one for an Uno:


and a Mega


Teensy 3.1


ATTinys


Raspberry Pi


NodeMCU

NodeMCU Pinout


Nano 33 IoT

 

Posted in c-arduino, c-tinys | 31 Comments

Code Upload to Arduino Mega hangs but Uploads Fine to Arduino Uno

I first hit this problem several years ago when writing a really big program that had to run on a Mega. Then I hit it again last night and had to try to remember the cause.

I believe this is a problem only on older Mega’s. I believe the new ones ship with a recent boot loader. The original one I had issue with 2+ years ago had come from china (an unrealized knock-off). The one I had trouble with last night was an old one at the local maker space.

This time I’ll document the fix here so next time I might be able to find the solution without referring to my faulting memory.

The basic issue is caused by having ‘!!!’ embedded in your code. The older boot loader uses this for something. Initially I did have a constant containing ‘!!!’. When I found the issue, I removed the constant, but i still had intermittent problems. The code was large enough that some of the code itself was just happened to contain the string. So fixing the boot loader was the only option.

These notes were taken largely verbatim from the software document I maintained during the project:

Arduino Mega 2560 “!!!” Problem

Here is a brilliant one: The boot loader for the Mega 2560 uses “!!!” for some special purpose. If you have that string in the code being uploaded, the upload will hang.

This has become a show stopper. although I yanked the literal “!!!” I was using periodically I still get object code generated with that sequence. Up to now I’ve been able to rearrange code to work around it, but now it is happening in the middle of a large array declaration and i cannot get around it. I am being forced to address the problem.

My immediate work around was to go back to the Arduino Mega which doesn’t have the bug. That is allowing me to continue development, but I need to fix the production board that the company purchased.

I researched the problem further and found that the boot loader has been patched. Here is the thread regarding the problem and patch:

http://code.google.com/p/arduino/issues/detail?id=392

and the code for the downloader:

http://www.xyfyx.com/files/stk500boot_v2_mega2560.hex

The problem is installing this boot loader. I can’t just do it with the hardware I have. One option is to purchase a bootloader programmer:

https://www.sparkfun.com/products/9825?

The other is to program an UNO to act as a programmer. Instructions for doing that are here:

http://www.sparkfun.com/tutorials/247

I also need all of the ‘fuse’ settings for the chip. I got these from boards.txt file that is in the arduino directory:

mega2560.name=Arduino Mega 2560 or Mega ADK

mega2560.upload.protocol=stk500v2
mega2560.upload.maximum_size=258048
mega2560.upload.speed=115200

mega2560.bootloader.low_fuses=0xFF
mega2560.bootloader.high_fuses=0xD8
mega2560.bootloader.extended_fuses=0xFD
mega2560.bootloader.path=stk500v2
mega2560.bootloader.file=stk500boot_v2_mega2560.hex
mega2560.bootloader.unlock_bits=0x3F
mega2560.bootloader.lock_bits=0x0F

mega2560.build.mcu=atmega2560
mega2560.build.f_cpu=16000000L
mega2560.build.core=arduino
mega2560.build.variant=mega

Here are instructions on using the monitor. Make sure baudrate is 11520

http://www.avr-developers.com/bootloaderdocs/index.html

Uploading Boot Loader with Pocket AVR Programmer

Purchased AVR programmer to resolve above error. Here are instructions from the sparkfun website:

To use this programmer, attach to a Windows machine and install the drivers listed below. Open a command prompt. Assuming WinAVR (and therefore AVRDUDE) have been installed, type:

avrdude -c usbtiny -B 1 -patmega328 -U flash:w:main.hex

Be sure to include the “-B 1” flag as this will significantly increase the programming speed! You may need to change -p flag to your appropriate microcontroller. You can setup a tool and hotkey in Programmers Notepad to do this automatically.

https://code.google.com/p/robot-exporers/source/browse/trunk/hardware/Programmers/Pocket+AVR+Programmer/AVR-Pocket-Programmer-v15.zip?r=485

I unzipped the above files into a new folder, plugged in the programmer, and pointed to that directory to find driver files. That worked fine.

AVRDUDE is located here:

C:\Program Files\Arduino-1.0.1\hardware\tools\avr\bin\

CD to that dir.

Move the HEX file to the avrdude directory.

connect cable to arduino, with cable going away from reset button.

connect USB cable to programmer.

Lights will turn on for both boards

To test the connection I type:

[C:\Program Files\Arduino-1.0.1\hardware\tools\avr\bin] avrdude -c usbtiny -p m2560 -C ..\etc\avrdude.conf -v

avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch

System wide configuration file is "..\etc\avrdude.conf"

Using Port                    : lpt1
Using Programmer              : usbtiny
Overriding Baud Rate          : 19200
avrdude: usbdev_open(): Found USBtinyISP, bus:device: bus-0:\\.\libusb0-0001--0x1781-0x0c9f
AVR Part                      : ATMEGA2560
Chip Erase delay              : 9000 us
PAGEL                         : PD7
BS2                           : PA0
RESET disposition             : dedicated
RETRY pulse                   : SCK
serial program mode           : yes
parallel program mode         : yes
Timeout                       : 200
StabDelay                     : 100
CmdexeDelay                   : 25
SyncLoops                     : 32
ByteDelay                     : 0
PollIndex                     : 3
PollValue                     : 0x53
Memory Detail                 :

Block Poll               Page      Polled
Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom        65    10     8    0 no       4096    8      0  9000  9000 0x00 0x00
flash         65    10   256    0 yes    262144  256   1024  4500  4500 0x00 0x00
lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

Programmer Type : USBtiny
Description     : USBtiny simple USB programmer, http://www.ladyada.net/make/usbtinyisp/
avrdude: programmer operation not supported

avrdude: Using SCK period of 10 usec
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9801
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as D8
avrdude: safemode: efuse reads as FD

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as D8
avrdude: safemode: efuse reads as FD
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

I saved the existing bootloader (in case I need to go back) by doing this:

[C:\Program Files\Arduino-1.0.1\hardware\tools\avr\bin]avrdude -B 1 -c usbtiny -p m2560 -C ..\etc\avrdude.conf -Uflash:r:oldbootloader.hex:i

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9801
avrdude: reading flash memory:

Reading | ################################################## | 100% 38.86s

avrdude: writing output file "oldbootloader.hex"

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

NOTE: the above looks like it worked, but it didn’t. The output file contains only a single line.

To install the new boot loader do the following:

[C:\Program Files\Arduino-1.0.1\hardware\tools\avr\bin] avrdude -B 1 -c usbtiny -p m2560 -C ..\etc\avrdude.conf -Uflash:w:stk500boot_v2_mega2560.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9801
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed

To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "stk500boot_v2_mega2560.hex"
avrdude: input file stk500boot_v2_mega2560.hex auto detected as Intel Hex
avrdude: writing flash (261386 bytes):

Writing | ################################################## | 100% 52.16s

avrdude: 261386 bytes of flash written
avrdude: verifying flash memory against stk500boot_v2_mega2560.hex:
avrdude: load data flash data from input file stk500boot_v2_mega2560.hex:
avrdude: input file stk500boot_v2_mega2560.hex auto detected as Intel Hex
avrdude: input file stk500boot_v2_mega2560.hex contains 261386 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 38.89s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x3e000
0x0d != 0xff
avrdude: verification error; content mismatch

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

NOTE the verification error above. This is OK. I don’t know why, but it is OK.

NOTE: you can also burn a new bootloader using the arduino IDE. Set board to correct board, set programmer to USBTinyISP and click on burn. Problem with this is it uses the default bootloader (found in booloader directory) which is wrong. I presume this can be replaced with the good one, but I haven’t played with that.

Posted in c-arduino | Leave a comment

Using a DG600F Coin Acceptor to Control EmulationStation Gaming Software

A group at the local STEM school has a project to build a gaming system. They are running EmulationStation on a Raspberry Pi which works very nicely. Everything is controlled by a joystick and pushbuttons. They are building into a wood console they cut on a CNC router.

They called me to help them integrate a coin acceptor into the game. The design and implementation of the coin acceptor was documented here

 

Interfacing DG600F Coin Acceptor to Arduino

So we have a signal coming into the RPI that is HIGH when there is time left and LOW when the time runs out. They needed to somehow not allow gaming to start until the signal goes HIGH and terminate it when it goes LOW.

First we looked at EmulationStation. They are using an IPAC-4 controller to convert the controls into keyboard keystrokes. There are a few connections there for a coin acceptor; however, we could find no documentation on how to make those work with EmulationStation. Since we only had 4 hours left to complete the program we had to move on.

Since we could not find any other method of using a coin acceptor I will document our solution. It is not elegant, but it works.

We decided the best course of action was to trap the call to EmulationStation. We would not execute the gaming software until $$$ was input and the control signal went HIGH. Then when the signal went LOW we would reboot the RPI.

The kids don’t know anything about linux outside of getting the gaming software installed. Searching the internet, we could not figure out what was causing EmulationStation to fire up.

Finally we found /etc/profile had been modified to start the program during boot up. We commented that line out.

We need to read GPIO4 pin, so we made the following configuration changes to the system:

sudo echo 4 >/sys/class/gpio/export
sudo echo in >/sys/class/gpio/gpio4/direction

We then used this scriplet to verify the pin was going high/low when we expected it:

while true;do
    cat /sys/class/gpio/gpio4/value
    sleep 1
    done

The final step was to create a script that starts when the user pi logs in. This script waits for coins to be dropped, plays the game, and then reboots the RPI when the time runs out.

#!/bin/bash

#these shouldn't be necessary every time, but they keep problems from cropping up for the kids down the road
sudo echo 4 >/sys/class/gpio/export
sudo echo in >/sys/class/gpio/gpio4/direction

clear
echo GamePlay Monitor. Waiting for coins....

while [[ $(cat /sys/class/gpio/gpio4/value) == '0' ]]; do
    sleep 1
    done

echo Starting Game

#start game as separate process
emulationstation &

while [[ $(cat /sys/class/gpio/gpio4/value) == '1' ]]; do
    sleep 1
    done

sudo reboot

this file was named gameplay. It had its permissions change to allow it to be executed. Finally, the last line of .bashrc in the pi users home directory had the line added:

/home/pi/gameplay

This is not pretty, but it works reasonably well. And we got it done with time to spare for them to work on some of the other parts.

As I was driving home I realized that rebooting the RPI was overkill. Instead of issuing a reboot, a killall emulationstation probably would have worked as well and not required an entire system boot.

Feb 2018 Update:

Circuit Cellar has written a 3 part series on money counting devices including the DG600F. The first is in the Dec 2017 (#329) issue.

http://www.cc-webshop.com/Circuit-Cellar-329-December-2017-PDF-FI-2017-329.htm

Posted in c-rpi | 10 Comments

CPLD/FPGA Programming for an Arduino Kind of Guy

For the past month I have been learning to program FPGAs. I had been thinking about doing this for a while, but couldn’t figure out how to get started. As it turns out, it isn’t too hard to do, but I needed something that would guide me through the whole process.

I started by reading Verilog By Example:

This is a very short, but well laid out book that explains the basics of programming FPGAs in Verilog. Once a bit of the mystery started to go away, it was time to try my hand at real hardware.

I followed the lessons found at

Lesson 1: Introduction to FPGA and CPLD

and purchased their parts kit as well:

Lesson 1: Introduction to FPGA and CPLD

The tutorial is designed to program an Altera MAX3000A CPLD. CPLDs are simpler versions of FPGAs. They don’t have as many logic gates but they also have the advantage of retaining their progamming when power is off.

For the most part, this was a very well done set of lessons that will get you through all of the fundamentals.

I purchased the tutorials on DVD and that was a waste. At DVD’s resolution of 720p, I really could not read the text. The same lessons are available on youtub in 1080p and those were crisp enough to allow reading the CRT.

My only issue was with the 3.3v 7555 clock being used. For reasons I still don’t understand, the MAX3000A didn’t seem to see all of the clock cycles unless I pushed it up to 5V. The tutorial works fine in 3.3V and I couldn’t find any other complaints like this.

I asked the tutorial author about this. He gave me a few suggestions to try and then went silent. Not that I expect hand-holding from what is essentially free training, but I am still perplexed as to the issue. None of the lessons using the clock worked properly for me at 3.3V – and that was with replacing all of the hardware – just in case.

I also went to the Altera website and did some of their free online training.

I am grateful to Pyro Electronics and Altera for making the educational materials free and for making the software tools free. This has purely been an exercise in curiosity. I have found it very interesting, but would never have been able to justify spending $100’s or $1000’s. $40 was just about perfect.

I now have enough knowledge of the process that I have purchased a better CPLD (several Altera MAXII models) and a couple of VHDL books (and a few Verilog books will be forth coming as well).

 

Posted in c-fpga | Tagged | 2 Comments

Interfacing DG600F Coin Acceptor to Arduino

I helped a kid at the local STEM school with this project. Sparkfun has a good video on getting the coin acceptor programmed, and they have a link to the datasheet which is fairly readable, but I could find no sample code anywhere so I thought I would post what we did for others.

The DG600F Coin Acceptor is available at Sparkfun. It looks like this:

This is a pretty cool little device. It was easy to program in coins and interface to the arduino. The only downside I see is it doesn’t make change. But if you are buying time, that is just fine.

Their project is to use an arduino to determine the dollar amount of coins input into the coin acceptor, then for every $.01, let a user play games on a raspberry Pi for a minute. We decided to let the Arduino count the dollar amount, decide how much time that would buy, then simply raise a pin HIGH when there was time left. That pin would be connected to the RPI and the RPI programmer could read that pin to decide if there is time left to keep playing.

The hardware is connected like this:

cointaccept-fig1

We configured the coin acceptor to output serial (moved dip switch 3 to on). It defaults to 4800 baud so we stuck with that and just made sure the code used the same baud rate. We programmed the coin acceptor for .01, .05, .10, and $.25. We tried $.50, but it got caught in the mechanism and decided not to try again.

The following code is quite simple. It reads coin amounts from the coin acceptor and uses that to increase a timer. As long as the timer is > 0, it keeps pin 13 high (which has an LED connected on the board to provide feedback that there is still time).

I wanted to allow the student to be able to use Serial.print to debug the code, so we used the SoftwareSerial library to use pin 2 to receive serial data.

#include <Arduino.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2,3); // RX, TX

int secondsRemaining = 0;
void setup() {
    // Open serial communications and wait for port to open:
    Serial.begin(9600);
    Serial.println("Coin Acceptor Ready!");

    // set the data rate for the SoftwareSerial port
    mySerial.begin(4800);

    pinMode(13, OUTPUT);

    }

void loop() {
    int i;
    unsigned long lastMillis = millis();

    while (true) {
        // any input coming from coin acceptor?
        if (mySerial.available()) {
            // read input, which is a 1 byte integer
            i=mySerial.read();
            // ignore any 255 amounts
            if (i != 255) {
                // increment time based on coin amount
                secondsRemaining = secondsRemaining + i * 60;
                Serial.print("Time Left is ");
                Serial.print(secondsRemaining);
                Serial.println(" remaining");
                }
            }
        if ((millis() - lastMillis) > 1000UL) {
            // decrement the time remaining by 1 sec
            lastMillis = millis();
            if (secondsRemaining > 0) {
                secondsRemaining = secondsRemaining - 1;
                }
            if (secondsRemaining > 0)
                digitalWrite(13, HIGH);
            else
                digitalWrite(13, LOW);
            Serial.print("Time Left is ");
            Serial.print(secondsRemaining);
            Serial.println(" remaining");
            }
        } // while

    }

 

Posted in c-arduino | Tagged | 18 Comments

Using the Teensy 3.1 Real Time Clock (RTC)

One of my interests in the Teensy is the built-in RTC. Especially since the RTC module I was using last summer with an arduino ended up loosing time pretty quick (as I recall it would loose an hour a week).

PJRC’s information on time and Teensy can be found here:

http://www.pjrc.com/teensy/td_libs_Time.html#teensy3

Setting up the Hardware

True to form, I didn’t really research the Teensy, I just bought it. So once I got it I found it doesn’t have RTC ability until you solder a crystal onto the board.

The recommended crystal is Citizen part CFS-206, Digikey part 300-8303-ND, 300-8762-ND, 300-8763-ND, or 300-1002-ND. I noticed Jameco sells a 32.768 kHz, 12.5 pF crystal as well. Since I already needed some parts from Jameco, I bought the crystal there.

It appears the Jameco crystal ended up being just a smidge too long to solder into place with the headers I already soldered into place. I placed the crystal on top, standing upright. That works so-so for me since some of the headers are about that tall as well. Next time I’ll order the right crystal.

Setting Up Software

Before soldering the crystal into position, I first tested the Teensy RTC. I did so using the TimeTeensy3 program found in File | Examples | Time.

Hello!? That was weird, the RTC was just a few minutes off from the real-time. Now how could that possibly be? The code waits for serial input and if it see ‘T’ <integer> it uses that to set the RTC. Evidently the teensy loader initially sent this data because there is no way I would have accidently typed in the correct 32bit unix time stamp. That’s my theory anyway.

I removed the code that gets the clock from PC and was able to see every time I rebooted the Teensy, it would start at the same date & time. Not 1972 like you would think, but the initial time it evidently retrieved from the PC.

At this point, I soldered on the crystal and hooked up the battery. I altered the TimeTeensy3 program to accept a time from the keyboard only if <CR> is pressed, and a prompt is sent to identify what is going on.

This program works fine. The Teensy starts up, setting the system clock from the Teensy RTC. The user can change the time using the serial port by simply pressing <CR>. To set the time, you need to know the current unix type stamp. This website will help you calculate that:

http://www.unixtimestamp.com/

Here is the source to the program I have running:

#include <Time.h>  

void setup()  {

  Serial.begin(9600);
  delay(100);

  Serial.println("Waiting for high DTR");
  while (!Serial.dtr()) {}

  setSyncProvider(getTeensy3Time);
  if (timeStatus()!= timeSet) {
    Serial.println("Unable to sync with the RTC");
    } 
  else {
    Serial.println("RTC has set the system time");
    digitalClockDisplay();
    Serial.println();
    }
  }

void loop() {
  
  time_t t;
  
  if (Serial.available()) {
    if (Serial.read() == '\r') {
      Serial.setTimeout(5000);
      Serial.print("Enter unix time stamp(input is not echoed):");
      t = Serial.parseInt();
      Serial.print("read: ");
      Serial.println(t);
      if (t != 0) {
        Serial.println("Setting RTC");
        Teensy3Clock.set(t);
        delay(100);
        setTime(Teensy3Clock.get());
        }
      }
    }

  digitalClockDisplay();  

  delay(1000);
  }

void digitalClockDisplay() {
  char s[40];
  
  snprintf(s,sizeof(s),"%02d/%02d/%02d %02d:%02d:%02d", 
    month(), day(), year(), hour(), minute(), second());
    
  Serial.println(s);    
  
  }

time_t getTeensy3Time() {
  return Teensy3Clock.get();
  }

Battery Power Loss

What happens if the battery is disconnected while the Teensy is off?

Noted the time on the Teensy, then cut power to it. 10 secs later I disconnected the battery. I then waited 1 minute to restore the power to the battery and another minute to restore power to the Teensy.

I would expect that either the time comes back as Jan 1, 1972 (time stamp of 0) or the time power was removed from the battery. Neither. The time came back as several minutes before I cut power to the Teensy.

I wondered if setting the RTC might change this initial value that is restored when the battery is restored. So I set the RTC on every second.

That had the curious effect of the Teensy starting with a future time.

So as far as I can tell, there is no rhyme nor reason to what the initial RTC will be set to when power is applied.

Battery Power Drain

My last question is to guesstimate the lifetime of the CR2032 battery.

If the Teensy has power, it doesn’t drain the battery. So if the Teensy is designed to run continuously, then the CR2032 battery is only used during power interruptions.

Connecting it to an ammeter, I find that when the Teensy has no power, it is consuming about 1.6 uA from the CD2032.

Energizer rates their CR2032 at 240mAh. Well, that comes in at 150,000 hours or 17 years. I’m sure that is overly optimistic, but it will certainly last for a couple of years.

Is it Accurate?

I will leave this project assembled and let it run for a while, then update this blog entry. I checked after about 12 hours and it looks like it is a few seconds slow, but I’ll let it run longer and see how it goes.

Update

I’ve spent the last couple of weeks playing with the clock to check its accuracy. Without touching it, it is not too bad. After 7 days I had lost 7 secs. This is pretty good to me. It would take 8.5 weeks before I had lost a minute. But we can make it better.

Looking at the docs for Teensy3Clock.compensate function, you provide it with a corrected PPM/8, PPM being parts per million.

Calculating this is not too difficult. If I lost 7 secs in 7 days, that is 7 secs in 604800 secs. The ratio would be 7:604800. To then get the PPM, multiply by 1M. So the error is 7/604,800 X 1,000,000 or 11.57PPM. Since the compensate function is ppm/8 I need to multiply 11.57PPM by 8 to get 92.59, rounded to an integer is 93 and that is my correction:

Teensy3Clock.compensate(93);

Note that I am using +93 because I need to speed the clock up. If I needed to slow it down 7 secs/week I would use -93.

 

Posted in c-tinys | Tagged , | 10 Comments

Telephone System Mechanical SXS Line Finder Video

Last spring I was in Oklahoma City. I flipped thru a website full of things to see and one was the Oklahoma Museum of Telephone History.

This ended up being a great tour. It is located in a room in the AT&T building and the guide had worked his way up through the ranks of Southwestern Bell. He was knowledgeable and entertaining.

I shot this video showing the mechanical dialing system in operations. I figured I’d stick it out on the web, in case any one every goes looking for such as thing.

More information on this can be found here.

Posted in c-retro | Tagged , | Leave a comment

Installing SNMP onto a Raspberry Pi

While researching DHCP problems, I noticed someone was discussing monitoring DHCP from SNMP. That left me wondering what the Raspberri Pi MIB looks like, so I decided to install SNMP and find out.

If you are not familiar with SNMP, it is an extensive monitoring protocol. I once used it heavily to monitor network performance across hundreds of routers. To best make use of SNMP, you need a SNMP Console such as SNMPc. SNMPc is rather spendy these days, but there are free SNMP consoles as well – they just take more work (from what I’ve seen) to get running.

For my purposes, I don’t need an SNMP console. I will just use a utility called SNMPWALK which will dump out the entire MIB in a semi-formatted fashion.

RPI does not come with SNMP installed. To install it:

sudo apt-get update
sudo apt-get install snmpd
sudo apt-get install snmp

To get it running, you will need to modify the /etc/snmp/snmpd.conf file:

First, I commented out this line:

#agentAddress  udp:127.0.0.1:161

and below the line ‘#agentAddress udp:161,udp6:[::1]:161′ I added:

agentAddress udp:161

then below this line:

 rocommunity public localhost

I added:

 rocommunity public 190.0.10.0/24

Finally, restart the service:

service snmpd restart

Verify the service has started:

ps -A | grep snmpd

If the service did not start, you can check \var\log\syslog for error messages.

You can also run tcpdump to monitor SNMP packets on the RPI to verify they are being received and respond to:

tcpdump -i eth0 “udp and (src port 161 or 162)”

On the RPI, you can walk the MIB using this command:

snmpwalk -Os -c public -v 1 localhost

Unfortunately, no MIBs appear to be installed to properly interpret the OIDs so you mainly get gibberish, but it is a good test to verify snmpd itself is working.

These instructions will fix the snmp client so that it extracts the english names for the OIDs:

https://wiki.debian.org/SNMP

Here is the system section of RPI’s MIB:

ysDescr.0 = STRING: Linux nsdude 3.12.28+ #709 PREEMPT Mon Sep 8 15:28:00 BST 2014 armv6l
sysObjectID.0 = OID: netSnmpAgentOIDs.10
sysUpTimeInstance = Timeticks: (33662) 0:05:36.62
sysContact.0 = STRING: Me <me@example.org>
sysName.0 = STRING: nsdude
sysLocation.0 = STRING: Sitting on the Dock of the Bay
sysServices.0 = INTEGER: 72
sysORLastChange.0 = Timeticks: (6) 0:00:00.06
sysORID.1 = OID: snmpFrameworkMIBCompliance
sysORID.2 = OID: snmpMPDCompliance
sysORID.3 = OID: usmMIBCompliance
sysORID.4 = OID: snmpMIB
sysORID.5 = OID: tcpMIB
sysORID.6 = OID: ip
sysORID.7 = OID: udpMIB
sysORID.8 = OID: vacmBasicGroup
sysORDescr.1 = STRING: The SNMP Management Architecture MIB.
sysORDescr.2 = STRING: The MIB for Message Processing and Dispatching.
sysORDescr.3 = STRING: The management information definitions for the SNMP User-based Security Model.
sysORDescr.4 = STRING: The MIB module for SNMPv2 entities
sysORDescr.5 = STRING: The MIB module for managing TCP implementations
sysORDescr.6 = STRING: The MIB module for managing IP and ICMP implementations
sysORDescr.7 = STRING: The MIB module for managing UDP implementations
sysORDescr.8 = STRING: View-based Access Control Model for SNMP.
sysORUpTime.1 = Timeticks: (4) 0:00:00.04
sysORUpTime.2 = Timeticks: (5) 0:00:00.05
sysORUpTime.3 = Timeticks: (5) 0:00:00.05
sysORUpTime.4 = Timeticks: (6) 0:00:00.06
sysORUpTime.5 = Timeticks: (6) 0:00:00.06
sysORUpTime.6 = Timeticks: (6) 0:00:00.06
sysORUpTime.7 = Timeticks: (6) 0:00:00.06
sysORUpTime.8 = Timeticks: (6) 0:00:00.06

To see information about RPI disks:

snmpwalk -Os -c public -v 1 nsdude UCD-SNMP-MIB::dskTablecd /

Information about CPU usage (load average):

snmpwalk -Os -c public -v 1 nsdude UCD-SNMP-MIB::laTable

Posted in c-rpi | Tagged , | 6 Comments

Wiring Teensy 3.1 and ENC28J60 Ethernet Module Together

The teensy is pretty cool, but with all that processing power, it needs to be able to do more than turn pins on and off to communicate. If I’m going to use this for anything truly useful, I’ll want it to send information over a network.

In this experiment, I figure out how to wire an ENC28J60 ethernet module to the Teensy 3.1. This is a 3.3V module and should work with the Teensy 3.0 as well, but don’t take my word for it – I haven’t tested it.

I have written about the ENC28j60 before. I have used it several times with an Arduino Nano. Depending on the software library, I’ve been able to get it to act as a client or server for both TCP and UDP. This link points to a recent blog entry regarding the ENC28J60:

TCP Communications between a PC and an Arduino Nano Using Lazarus / Free Pascal

The ENC28J60 I am using for this project is a bit different from the others I have used in the past. It is NOT an Arduino Nano shield. It is just a little stand-alone module. It looks about like this:

Teensy-enc28j60-module

I purchased mine from eBay from a seller located in the US for about the going Chinese price:

http://www.ebay.com/itm/331199261232?_trksid=p2060778.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

Mine didn’t have mounting holes. Next time I’ll make sure I find one with holes.

I went searching the web for instructions on interfacing the Teensy to the ENC28J60. I didn’t find anything, but I did find someone who had interfaced the Teensy to a normal Arduino ethernet shield. CLOSE ENOUGH! Here is a link to those instructions:

http://www.epyon.be/2013/07/06/using-the-teensy-3-0-with-the-arduino-ethernet-shield/

Using those instructions, and the pin descriptions on the two boards, I came up with this wiring diagram:

Teensy-enc28j60-wiring

You might find the official Teensy Pinout chart useful as well:

Wired up, it looks like this. You can click on the pic to get a much bigger version:

Teensy-enc28j80-pic

Once I had it wired, I then opened the UIPEthernet TCP Server example code. I simply changed the IP address to something that would work on my local network and compiled/uploaded.

Worked great! Pinged and connected to it on the first try.

Posted in c-tinys | Tagged , | 7 Comments

Teensy 3.1 – Emulating a USB Keyboard

My primary motivation for purchasing a Teensy is to emulate a keyboard to set up a little practical joke for someone.

So I need to get the Teensy running in a manner in which if I press a button, it will transmit text as if it were a keyboard attached to the PC.

This turns out to be quite easy. I have a push button switch attached to PIN 2 of my Teensy and I will be using the bounce library to read and debounce the switch.

Here is the code:

#include <Bounce.h>
int sw = 2; 
Bounce swBounced = Bounce(sw, 10); 

void setup() {                
  pinMode(sw, INPUT);
  digitalWrite(sw, HIGH);
  }

void loop() {
  swBounced.update();
  if (swBounced.risingEdge()) { // due to negative logic, button released on rising edge
    Keyboard.print("Hello World "); 
    }  
  }

The action is all in the Keyboard.print statement. This is like the normal Arduino Serial.print statement except instead of transmitting the output to a USB serial port, it is going to transmit the output as if it where a keyboard.

Before compiling, you have to make sure the USB type is set to keyboard+mouse+joystick:

Teensy-FL-Fig15

Now just compile and run as normal. Place the cursor into a window you don’t mind seeing ‘hello world’ in, and press the button:

Teensy-FL-Fig16

The various methods for the Keyboard class can be found here:

http://arduino.cc/en/Reference/MouseKeyboard

 

 

Posted in c-tinys | Tagged , | 1 Comment