Category Archives: Uncategorized

Weekly update

Dealing with PC issues at the moment so this week has been a bit rough.

My inspiration for the Portable Raspberry Pi came from the Ben Heck Show on Ben’s creation of a Portable Pi. (Part 1 & Part 2) I liked Ben’s design but there were a few things that I wanted to change.

  1. I did not want to deal with having a batteries in series and not be able to easily charge them in the case without disconnecting them from the device. This requirement was due to Ben’s choice of LCD monitor so I am changing the LCD to an Adafruit PiTFT screen which uses SPI. This will be a bit trickier to use but should not be a problem.
  2. I wanted to use the powerful Teensy for more than just the gamepad so I modified the Teensy code to provide a custom gamepad which has only the buttons that I will have plus provides keyboard and raw HID devices. The reason for these additional devices are for power management and control.
  3. Power – I wanted to be able to charge the battery in the device and still be able to use the device while it was charging. To implement this requirement, I turned to Adafruit’s USB LiIon/LiPoly charger.
  4. Power On/Off – The Portable Pi will be used by my children so I wanted to have an easy way for them to shut it down as well as to automatically shut it down when the batteries are low. This is where the additional Keyboard and Raw HID device come in on the Teensy. The plan is to implement a soft latching power switch circuit which can turn on the power to the device when pressed from an off state. When it is on, the Teensy will be able to detect when it is pressed and start an orderly shutdown of the Raspberry Pi. If the button is held down longer, about 3 seconds, then the power will be switched off. This will allow it to function much like the power switch on a PC or laptop.
  5. Power monitoring – I would also like to be able to monitor the battery level and perform an automatic shutdown of the Raspberry Pi if the voltage is too low. This is where the Raw HID device comes in. I plan to use the Teensy to monitor the battery voltage and send periodic updates to the Pi to let it know the level. If the level reaches a min threshold then it will send keypresses through the keyboard device to tell the Pi to shutdown.

These are just a few of the high level requirements I have for the Portable Pi. So far, I have the Gamepad code completed and the hardware on a breadboard. I am currently working on the soft latching power switch. I have built a few circuits which work but only at 5 VDC. I need it to work at 3 VDC and higher so I need to order some parts as I do not have MOSFETs which will switch full on at that low of a voltage. I plan to implement a design found on Mosaic Documentation Web. I have built a similar circuit and found it to work well and meet the requirements that I have. I also looked at David Jones’s design on his EEVBlog but it did not meet all of the requirements that I have. It is a nice simple design so I am certain I will use it in the future on another project.

Updates and Future Plans for this Blog

Well, I have done a terrible job keeping this blog up to date so I will try once again to do a better job. I plan to update this blog at least once a week by adding an update even if I feel there is not much to report. The plan is to do a blog entry each Monday by 10 PM EST.

Some updates since my last blog post.

I have managed to be on Adafruit’s Show and Tell a few times. Adafruit’s Show and Tell is hosted by Google Plus Hangouts.

  • 18 Jan 2014: Pinewood Derby Car
  • 26 Nov 2014: Guggenhat with mods
  • 31 Dec 2014: LED Matrix Clock and Eiffel Tower Alarm Clock
  • 11 March 2015: Power Supply

I am currently working on a Portable Pi. It is a slightly different design than any of the others I have seen posted online. Most likely the next few posts will be regarding the build of the Portable Pi. Once that is completed, I plan to post a few of the builds mentioned in the Adafruit Show and Tell segments such as the power supply, Guggenhat mods, and LED Matrix Clock mod.

Raspberry PI B+

Hardware

Needed

  • Raspberry Pi
  • MicroSD Card 4GB or larger
  • USB Keyboard
  • USB Power Supply and cable with micro USB Connector
  • Display (Composite or HDMI)
  • Display cable (Type of cable depends on monitor)
  • MicroSD Card to SD Card Adapter (Needed only if your PC has a SD Card Reader but not a MicroSD Card Reader)

Nice to Have

  • Raspberry Pi B+ Case (Note cases for other models may not work)
  • WiFi module or Ethernet Cable

Steps

  1. Download the Raspbian Image from http://www.raspberrypi.org/downloads/ (As of this post, the file is 2014-06-20-wheezy-raspbian.zip)
  2. Unzip the Raspbian Image File
    Image2
  3. Follow the instructions at http://www.raspberrypi.org/documentation/installation/installing-images/README.md for your operating system. I will be using Windows and will mirror the steps from the installation instructions page

Windows Installation

  1. Insert your MicroSD card into the card reader on your PC (NOTE: You may need a MicroSD to SD Card Adapter)
  2. Download the Win32DiskImager utility from http://sourceforge.net/projects/win32diskimager/ (As of this post, the file is Win32DiskImager-0.9.5-install.exe)
  3. Install the Win32DiskImager Utility by double clicking the downloaded file
  4. Click on the “Next >” button on the setup wizard
    Welcome to the Win32DiskImager Setup Wizard
  5. Select the “I accept the agreement” radio button and click the “Next >” button
    License Agreement
  6. Click the “Next >” button on the destination location dialog
    Select Destination Location
  7. Click the “Next >” button on the Select Start Menu Folder dialog
    Select Start Menu Folder
  8. If you do not want a desktop shortcut, uncheck the “Create a desktop icon” checkbox
  9. Click the “Next >” button on the Select Additional Tasks dialog
    Select Additional Tasks
  10. Click the “Install” button on the Ready to Install dialog
    Ready to Install
  11. Wait for the installation to complete
    Installing
  12. Click the “Finish” button on the Completing the Win32DiskImager Setup Wizard dialog
    Completing the Win32DiskImager Setup Wizard
  13. It is possible that you may see the following error message
    Unable to execute file
  14. If you see the error message above
    1. Click the “OK” button
    2. Right-click on the desktop shortcut and select “Run as administrator” from the pop-up menu
      Run as administrator
    3. When the User Access Control dialog is displayed, click the “Yes” button
      User Access Control dialog
  15. The application is now open
    Win32 Disk Imager
  16. Click the folder icon and select the Raspbian image file downloaded earlier
    Selecting the image file
  17. Select the drive letter for your MicroSD Card
    WARNING: Be very careful to select the correct drive letter as the utility will erase all data on the drive! You have been warned!
    Select the MicroSD Card
  18. Click the “Write” button
    Write the image
  19. Click the “Yes” button on the confirmation dialog
    Confirm Write
    If you see the following error (), check that there are no open Explorer Windows or other applications attempting to access the SD Card
    Write Error
    If you see the following error, check the write lock switch on the MicroSD Card Adapter
    Lock Error  SD Card Lock Switch
    Wait for the process to complete
    Wait
  20. When the process is complete, click the “OK” button
    Write Sucessful
  21. The main window will display the status as “Done.” Click the “Exit” button to exit the utility
    Done.
  22. Eject the MicroSD Card

Once the Raspbian Image has been written to the MicroSD Card, you are ready to boot and configure the Operating System (OS).

Booting and Configuring the Raspberry Pi using Raspbian OS

  1. Insert the MicroSD Card in the Raspberry Pi
  2. Connect the monitor, keyboard, mouse (optional), and power
  3. The Raspberry Pi Software Configuration Tool (raspi-config) will launch

A look at Adafruit’s Electret Microphone Amplifier – MAX4466 with Adjustable Gain (1063)

I purchased Adafruit’s Electret Microphone Amplifier – MAX4466 with Adjustable Gain (1063) and wanted to incorporate the circuit into a board that I am making to make a sound responsive decorative light. I saw a post from Adafruit that stated that the schematic was taken directly from the datasheet however looking at the component values on the board, it was obvious that some values had been changed. After a bit of reverse engineering of the board, it was confirmed that the schematic is indeed Figure 2 from the datasheet.

Figure2

Board Layout

Component Listing (Note Capacitor Values taken from Datasheet Schematic and not verified)

      • IC1 – MAX4466
      • R1 – 1KΩ
      • R2 – 1KΩ
      • R3 – 1MΩ
      • R4 – 1MΩ
      • R5 – 1KΩ
      • R6a – 500KΩ
      • R6b – 22KΩ
      • C1 – 0.1µF
      • C2 – 0.01µF
      • C3 – 1µF
      • C4 – 100pF
      • L1 – Ferrite Bead
      • L2 – Ferrite Bead

I wrote a simple program on the Arduino to capture 100 points of data per second for one minute and write the results to the serial output.

// Based on the Adafruit Trinket Sound-Reactive LED Color Organ
// http://learn.adafruit.com/trinket-sound-reactive-led-color-organ/code

#define MIC0_PIN 0 // Microphone is attached to Trinket GPIO #2/Gemma D2 (A1)
#define MIC1_PIN 1 // Microphone is attached to Trinket GPIO #2/Gemma D2 (A1)
#define DC_OFFSET 0 // DC offset in mic signal - if unusure, leave 0
#define NOISE 30 // Noise/hum/interference in mic signal
#define SAMPLES 60 // Length of buffer for dynamic level adjustment

int pointsPerSecond=100;
int captureMinutes = 1;
int delayMS = 1000/pointsPerSecond;
int datapoints=pointsPerSecond * captureMinutes * 60;
int curIdx=0;

void setup() {
 // put your setup code here, to run once:
 Serial.begin(57600);
 while (!Serial) {
 ; // wait for serial port to connect. Needed for Leonardo only
 }
 Serial.println(F("Idx\tAdaFruit\tMAX4466"));
}

void loop() {
 
 if(curIdx < datapoints)
 {
 // put your main code here, to run repeatedly:
 int adaFruitMic = analogRead(MIC0_PIN); // Raw reading from mic
 int max4466Mic = analogRead(MIC1_PIN); // Raw reading from mic
 
 Serial.print(curIdx);
 Serial.print(F("\t"));
 Serial.print(adaFruitMic);
 Serial.print(F("\t"));
 Serial.println(max4466Mic);
 
 curIdx++;
 delay(delayMS);
 if(curIdx >= datapoints)
 Serial.println("End of Sample");
 }
}

Here is the circuit diagram for the first test with values from the datasheet.

TestSchematic01

Test Schematic 1 – Values from datasheet

At first, I tried to use the values from the datasheet and noticed that the gain was not as high as the Adafruit module.

Test01_Chart01

Adafruit (ID: 1063) and MAX4466 Typical Schematic

Test01_Chart02

Adafruit (ID: 1063) Capture

Test01_Chart03

MAX4466 Schematic from Datasheet

Modified values to be close to the values used by the Adafruit 1063 module. The results showed that the gain was much better so these values will be good enough for my application, If you need to use this for a different application where you need better performance, you may want to look into the RC values. By modifying the capacitor values, it may be possible to achieve a cleaner output.

TestSchematic02

Modified resistor values to match Adafruit 1063 module

Test02_Chart01

Adafruit (ID: 1063) and MAX4466 Typical Schematic modified values

Test02_Chart02

Adafruit (ID: 1063)

Test02_Chart03

MAX4466 Typical Schematic modified values

This is not a thorough analysis of the performance of these two circuits but as stated above, it was good enough to give me the performance that I needed. (Test with Datasheet Figure 2)

BTW: The values read by the Arduino ADC are between 0 and 1023. The signal is centered around 511 and  has a noise level of ±50.

FYI: The gain for the circuit may be calculated as:

Gain = Rf/Rin = R6/R5 = 100KΩ/10KΩ = 10 (Dtasheet Circuit)

Gain = Rf/Rin = R6/R5 = 120KΩ/1KΩ = 120 (Modified Circuit)

You can also see from the graphs that the amplifier is driven to saturation. For my application that is acceptable but it may not be acceptable for your application particularly if you are creating a purely audio application.

Arduino Due Issues

I have been working with the Arduino Due and version 1.5.2 of the Arduino IDE. I have been attempting to port a mini digital picture frame that I wrote for the Arduino Micro and have not been having much luck. The problem is that the Arduino Due is still relatively new and is a different family than the previous Arduinos.

The errors that have been encountered due to references to the avr libraries. (In particular avr\io.h and avr/pgmspace.h.)

In my attempt, I did the following:

  1. Created the program shown below to workout the library issues. Once I am able to resolve the library issues, I will be able to start porting the code.
  2. Replace the Adafruit_ST7735 library with the modified version at https://github.com/sngl/Adafruit-ST7735-Library” target=”_blank which has been modified to support the Arduino Due
  3. Update the Adafruit_GFX library with the changes found at https://github.com/elechouse/Adafruit-GFX-Library/commit/69e355325312a57412d8c4d0ec6298aa3b4ed917
  4. Create a new folder in the Arduino IDE location at hardware/arduino/sam/cores/arduino/avr/
  5. Create a new file at hardware/arduino/sam/cores/arduino/avr/pgmspace.h and enter contents found at https://github.com/arduino/Arduino/commit/0f5a5259ec038537ea51de0059e711fdeebc6ece

Some issues are resolved but others remain.

Code

#include <Adafruit_GFX.h> // Core graphics library // OK after changes to libraries
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h> // OK
// #include <SD.h>

void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}


Errors

In file included from sketch_may19a.ino:20:
C:\arduino-1.5.2\libraries\Adafruit_ST7735/Adafruit_ST7735.h: In member function 'uint16_t Adafruit_ST7735::Color565(uint8_t, uint8_t, uint8_t)':
C:\arduino-1.5.2\libraries\Adafruit_ST7735/Adafruit_ST7735.h:116: error: 'newColor' was not declared in this scope

Commented line 20 in the Adafruit_ST7735.h file as the Color565 function does not appear to be called elsewhere and the newColor function does not exist in any libraries. The following errors are then produced.

C:\arduino-1.5.2\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp: In member function 'void Adafruit_ST7735::commonInit(uint8_t*)':
C:\arduino-1.5.2\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:266: error: cannot convert 'volatile RwReg*' to 'volatile uint8_t*' in assignment
C:\arduino-1.5.2\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:268: error: cannot convert 'volatile RwReg*' to 'volatile uint8_t*' in assignment
C:\arduino-1.5.2\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:276: error: 'SPI_CLOCK_DIV4' was not declared in this scope
C:\arduino-1.5.2\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:283: error: cannot convert 'volatile RwReg*' to 'volatile uint8_t*' in assignment
C:\arduino-1.5.2\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:285: error: cannot convert 'volatile RwReg*' to 'volatile uint8_t*' in assignment

Why is it when people provide fixes they are rarely documented completely? This is one of the most frustrating things that I encounter. I can solve these issues if given enough time but unfortunately I do not have the luxury. I will come back to this later and attempt to resolve the remaining issues.

Here is a post of someone else trying to get the Adafruit display to work with the Arduino Due. http://21stdigitalhome.blogspot.com/2013/02/arduino-due-spi-display-nearly-defeated.html

To be fair, the Arduino Due is a totally different architecture and it will take time to port the libraries over to the new architecture. I hope to get some more time later to tackle this problem again as this is a great opportunity to learn more about the Arduino Due but I suspect that I will not be able to devote the time I need to accomplish much.

Setting up the WiFi Part I – Supported Adapters

Video Coming Soon

This entry is for configuring the Asus USB-N10 USB Wireless-N USB Adapter. If you have any other WiFi adapter please refer to Chapter 4 Network Configuration of the Raspberry Pi User Guide book or perform Google Searches for your adapter.

003_001

NOTE: There is a WiFi Config tool included with Raspbian “wheezy” distribution however I have not had much luck with it. I t did work one time for me and that was it. You may give it a try but I recommend using the steps below as they have worked 100% of the time for me.

 

You will need to perform these steps from the command line. If you have the desktop loaded, open a terminal window by double clicking on the the LXTerminal shortcut on the desktop.

  1. At the command line, type the following command and press enter to view available wireless networks.
    sudo iwlist scan | less
  2. On the wlan interface, you will see the SSIDs listed on the lines starting with ESSID:. Verify that the network you wish to connect to is listed.
    003-002
  3. Press Ctrl+z to return to the command line
  4. Edit the network configuration file by typing the following command and press enter.
    sudo nano /etc/network/interfaces
  5. You should see the following content in the interfaces file.
    auto loiface lo inet loopback
    iface eth0 inet dhcpallow-hotplug wlan0
    iface wlan0 inet manual
    wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
    iface default inet dhcp

     

  6. Replace the bottom block with the following.
    auto wlan0
    iface wlan0 inet dhcp
    wpa-conf /etc/wpa.conf

     

  7. The resulting file should have the following contents.
    auto loiface lo inet loopback
    iface eth0 inet dhcpauto wlan0
    iface wlan0 inet dhcp
    wpa-conf /etc/wpa.conf

     

  8. Save the file and exit
    • Press Ctrl+o
    • Press Enter
    • Press Ctrl+x
  9. Now edit the wpa.conf file by typing the following command and pressing enter.
    sudo nano /etc/wpa.conf
  10. Enter the following for the contents of your file based on the type of security used by your WiFi network.
    NOTE: Do not type the word [Tab]. It indicates that you need to include a tab.

    No Encryption network={
    [Tab] ssid=”Your_SSID
    [Tab] key_mgmt=NONE
    }
    WEP Encryption network={
    [Tab] ssid=”Your_SSID
    [Tab] key_mgmt=NONE
    [Tab] wep_key0=”Your_WEP_Key
    }
    WPA/WPA2 Encryption network={
    [Tab] ssid=”Your_SSID
    [Tab] key_mgmt=WPA-PSK
    [Tab] psk=”Your_WPA_Key
    }

     

  11. Save the file and exit
    • Press Ctrl+o
    • Press Enter
    • Press Ctrl+x
  12. Connect to the wireless network by typing the following command and pressing enter.
    sudo ifup wlan0
  13. If you see the message “ifup: interface wlan0 already configured,” type the following command and repeat the previous step again.
    sudo ifdown wlan0
  14. If you are successful, you will see several lines starting with DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 … with the last line stating that the adapter is bound to an IP address on your network
    .
    003-003
  15. If you are successful at this point, you may close the terminal window and open a web browser to verify that you are connected to the internet.
    003-004