Brooke's World The life and ramblings of Brooke.

December 21, 2020

Learning about the Pillow Python Library

Filed under: Uncategorized — Brooke @ 11:41 am

Spending some time brushing up on Python.  Spent some time learning about the Pillow 8.0.1 library in Python 3.9.1.

The image I started with.

from PIL import Image
import os

if __name__ == '__main__':
    # Open an image to get some basic info
    infile = "images/numbers-tiger-populations.jpg"
    im = Image.open(infile)
    print(f"""
bits {im.bits}
mode {im.mode}
size {im.size}
    """)

    # Show the image using the local viewer
    input("Press enter when you are ready to see the image.")
    im.show()

    # Create a thumbnail
    size = (128, 128)
    outfile = os.path.splitext(infile)[0] + ".thumbnail"
    with Image.open(infile) as im:
        im.thumbnail(size)
        im.save(outfile, "JPEG")

    # Show the thumbnail
    im = Image.open(outfile)
    input("Press enter when you are ready to see the thumbnail.")
    im.show()

    # convert to grayscale
    im = Image.open(infile).convert('LA')

    # Show the grayscale
    input("Press enter when you are ready to see the grayscale.")
    im.show()

June 8, 2017

SensorBoard v2 final board test section complete

Filed under: Uncategorized — Brooke @ 9:33 pm

I wrote the test sketch for the SN74HC595 and it works.  All sections of the SensorBoard v2 have tested as working.  My next task will be to write some firmware that takes advantage of all 5 sections.  Two temperature sensors, FRAM, photo resistor, and shift register with 8 LEDs.

 

SensorBoard physical design issue

Filed under: Uncategorized — Brooke @ 9:15 pm

Thought I would share a design mistake for the TeensyBreakout w/ SensorBoard v2. It turns out it is a good idea to keep in mind the physical design of your boards when you plan to stack them. I thought I had done pretty well, until I needed to press the reset button! That’s right. It took some creative re-purposing of an ink pen by borrowing its refill to sneak in there and press the button. I am thinking the rev 3 SensorBoard needs to either have a hole that goes through every single “shield” or bring a reset button up to at least the Teensybreakout.

 

June 6, 2017

SensorBoard v2 bringup

Filed under: Uncategorized — Brooke @ 2:05 pm

I tested each of the Arduino sketches with the SensorBoard v2 on a Teensy 3.2 and they all worked. They covered both I2C temp sensors, the SPI FRAM, and the analog-read photoresistor ( values from about 20-1020 ).

The only chip I didn’t have a sketch written for yet was the SN74HC595 shift register. I am working on that sketch next.

June 2, 2017

Completed build of SensorBoard v2 for Contextual Electronics

Filed under: Contextual Electronics — Brooke @ 4:34 pm

I had time last night to work in the SensorBoard v2. I was able to laser cut the stencil, paste, place, reflow and visually inspect. Next stop will be to plug it in and test. During the fab downtime, I have been writing test applications for all the different sections. This should shorten my bring up time.

This board is a replacement due to issues  ran into where the copper was exposed outside of the pads that caused shorts to ground in many places.  It turns out that at some point, KiCAD changed a default setting which caused the issue.  You can read more about it on the CE forums.

May 27, 2017

Testing SN74HC595 shift register with Bus Pirate

Filed under: Uncategorized — Brooke @ 4:54 pm

As part of the CE Header project from the CE Skills course , we have a shift register on the SensorBoard. This chip allows us to light up 8 LEDs ( more with chip chaining ) with 3 pins.  I used a Bus Pirate (Dangerous Prototypes) and probes, from Seeed Studio, to iteratively poke at it until I understood how to talk to it via SPI.

I used a DIP version of the chip in a breadboard and wired it up to the Bus Pirate.  The LEDs are in the breadboard to see it working. Please note, the cable and connectors in the image below are from the Seeed probe cable. Some of the other probe cables have the colors in a different order on the connectors.

I used putty to connect to the Bus Pirate via a mini usb cable.

Note: If you decide to hook this up to an Arduino for testing, using an example sketch, here are the pins to use for your reference:

BP MOSI=pin 11
BP CLK=pin 12
BP CS=pin 8

Command What it does
Initalize the Bus Pirate
M 5 1 1 2 1 2 2
  • Mode SPI
  • Speed 30khz
  • Clock: Idle low *default
  • Output clock edge: Active to idle *default
  • Input sample phase: Middle *default
  • CS: /CS *default, Output Type: Normal (H=3.3V, L=GND)

Make sure the mode number you use is for SPI

W Turn on power, don’t forget this.  If you try to access the FRAM chip before this, you will likely hang the Bus Pirate and have to unplug/plug,setup.

 

Command What it does Output
Turn on output pins
[ 0b00000001 ] Turn on LEDs.  Bit 1 is QA and bit 8 is QH.
QH QG QF QE QD QC QB QA
               
0 0 0 0 0 0 0 1
[ 0b10000000 ] Turn on LEDs
QH QG QF QE QD QC QB QA
               
1 0 0 0 0 0 0 0
[ 0b10101010 ] Turn on LEDs
QH QG QF QE QD QC QB QA
               
1 0 1 0 1 0 1 0
[ 0b00000000 ] Turn all LEDs off
QH QG QF QE QD QC QB QA
               
0 0 0 0 0 0 0 0

 

Looking from the right side

Looking from the left

 

 

Testing MB85RS64V with Bus Pirate

Filed under: Uncategorized — Brooke @ 1:22 pm

As part of the CE Header project from the CE Skills course , I decided to add an IC that used SPI to the SensorBoard. I chose the MB85RS64V chip. This is a Ferroelectric Random Access Memory (FRAM) integrated circuit.  It is similar to FLASH, but with some added benefits. The idea is to be able to write data to it and the data will persist between power off and power on cycles. I used a Bus Pirate (Dangerous Prototypes) and probes, from Seeed Studio, to iteratively poke at it until I understood how to talk to it via SPI.

Once I soldered the MB85RS64V to a small carrier board from Adafruit, I placed it on a breadboard and wired it up to the Bus Pirate. Please note, the cable and connectors in the image below are from the Seeed probe cable. Some of the other probe cables have the colors in a different order on the connectors.

I used putty to connect to the Bus Pirate via a mini usb cable.

Command What it does
Initalize the Bus Pirate
M 5 1 1 2 1 2 2
  • Mode SPI
  • Speed 30khz
  • Clock: Idle low *default
  • Output clock edge: Active to idle *default
  • Input sample phase: Middle *default
  • CS: /CS *default, Output Type: Normal (H=3.3V, L=GND)

Make sure the mode number you use is for SPI

W Turn on power, don’t forget this.  If you try to access the FRAM chip before this, you will likely hang the Bus Pirate and have to unplug/plug,setup.

 

Command What it does Output
Read the ID
[ 0b10011111 r:4 ] Read Chip ID 0x04 0x7F 0x03 0x02

Manufacturer 0x04 Fujitsu
Continuation Code 0x7F ?
Product ID – byte 1
  Proprietary (3 left bits) 0b000 ?
  Density (5 right bits) 0b0011 64kbit
Product ID – byte 2 0x02 2

 

Command What it does Output
Read the status register
[ 0b00000101 r:1 ] Read the register 0x00 (default)

 

Command What it does Output
Read memory
[ 0b00000011 0 0 r:5 ] Read 5 bytes starting at address 0x00 0x00 (msb first) 0x00 0x00 0x00 0x00 0x00

Bytes are initialized to 0 from the manufacturer

[ 0b00000011 0 0 r:8192 ] Read all of the bytes from the chip

 

Write 1 byte to memory
Command What it does Output
[ 0b00000110 ] Write Enable
[ 0b00000010 0x1F 0xFF 0x11 ] Write 5 bytes starting at address 0x1F 0xFF (msb first)  Note: the very last byte is at address 0x1F 0xFF
[ 0b00000100 ] Write Disable
[ 0b00000011 0x1F 0xFF r:1 ] Read the data back from address 0x1F 0xFF 0x11

 

Write 5 bytes to memory
Command What it does Output
[ 0b00000110 ] Write Enable
[ 0b00000010 0x00 0x00 0x01 0x02 0x03 0x04 0x05] Write 5 bytes starting at address 0x00 0x00 (msb first)  Note: the very first byte is at address 0x00 0x00
[ 0b00000100 ] Write Disable
[ 0b00000011 0x00 0x00 r:5 ] Read the data back from address 0x00 0x00 0x01 0x02 0x03 0x04 0x05

 

Go ahead and power off with the w command, unplug the USB from the Bus Pirate, plug it back in.  Go through the set up steps and re-read the data, it should still be there!

It turns out that Adafruit sells this chip ready to go on a breakout board along with an Arduino library!

 

May 9, 2017

MillaMilla_DS7505_Library for Arduino

Filed under: Uncategorized — Brooke @ 7:16 pm

I released my very first Arduino library that can be found right in the Arduino IDE without having to download it and install it manually!  You can still download it and install manually if you like.  It supports the DS7505 temperature sensor.

Many thanks to Adafruit as I started with their MCP9808 library as my template.  I purchase from Adafruit several times a year.  Their products, service, and commitment to education is first class!

To add the library to your project, choose Sketch | Include Library | Manage Libraries … | Search for DS7505

The library supports basic functionality for the DS7505 Temperature Sensor.  Once you install the library, you can open the example sketch and go.

Here’s what the example looks like:

/**************************************************************************/
/*!
This is a demo for the DS7505
----> https://www.maximintegrated.com/en/products/analog/sensors-and-sensor-interface/DS7505.html

This code derived from the Adafruit_MCP9808_Library.

Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
/**************************************************************************/

#include <Wire.h>
#include "MillaMilla_DS7505.h"

// Create the DS7505 temperature sensor object
MillaMilla_DS7505 tempsensor = MillaMilla_DS7505();

void setup() {
  delay(2000); // helpful on Teensy debugging to give time to open the serial monitor
  Serial.begin(9600);
  Serial.println("DS7505 demo");
  
  // Make sure the sensor is found, you can also pass in a different i2c
  // address with tempsensor.begin(0x48) for example
  if (!tempsensor.begin()) {
    Serial.println("Couldn't find DS7505!");
    while (1);
  }
}

void loop() {
  //Serial.println("wake up DS7505.... "); // wake up DS7505 for normal power use
  //tempsensor.wake();   // wake up, ready to read!  If you don't wake when shutdown, you still get a temp reading, it will be the last reading while awake.

  //tempsensor.write8(DS7505_REG_CONFIG, DS7505_REG_CONFIG_CONVRESOL_12_BITS); // change default precision from default of 9 bits

  // Read and print out the temperature, then convert to *F
  float c = tempsensor.readTempC();
  float f = c * 9.0 / 5.0 + 32;
  Serial.print("Temp: "); Serial.print(c); Serial.print("*C\t"); 
  Serial.print(f); Serial.println("*F");
  
  //Serial.println("Shutdown DS7505.... ");
  //tempsensor.shutdown(); // shutdown DS7505 for low power
  
  delay(1000);
}

 

If you have a library you would like added to the Arduino IDE, check out the Library Manager FAQ.  It is a very easy to follow reference.  It only took about 2 1/2 days from when I created my issue for it to be found by the IDE.  Thank you to the Library Manager Team!!

May 6, 2017

Testing DS7505 with Bus Pirate

Filed under: Contextual Electronics — Brooke @ 4:53 pm

As part of the CE Header project from the CE Skills course , I needed to learn to work with DS7505.  I used a Bus Pirate (Dangerous Prototypes) and probes, from Seeed Studio, to iteratively poke at it until I understood how to talk to it via I2C.

Once I soldered the DS7505 to a small carrier board from Adafruit, I placed it on a breadboard and wired it up to the Bus Pirate.  Please note, the cable and connectors in the image below are from the Seeed probe cable.  Some of the other probe cables have the colors in a different order on the connectors.

I used putty to connect to the Bus Pirate via a mini usb cable.

Command What it does
Initalize the Bus Pirate
m 4 1 Mode, I2C, Speed 5khz
W Turn power on
P Turn on pull ups

 

Command What it does Output
Find the I2C address
(1) Find the slave address 0x90(0x48 W) 0x91(0x48 R)

 

Command What it does Output
Working with the Config register
[ 0x90 0x01 [ 0x91 r:1 ] Read the register 0x00 (default)
[ 0x90 0x01 0x60 ] Enable 12 bit resolution
[ 0x90 0x01 0x60 [ 0x91 r:1 ] Enable 12 bit resolution and read back current config  0x60

 

Command What it does Output
Working with the temperature register
[ 0x90 0x00 [ 0x91 r:2 ] Read the register ex:  0x19 0xE0
 

How to calculate given: 0x19 0xE0 and 12 bit resolution.

Bit 8 of MSB is the sign. 0=+ and 1=-
MSB is whole number
LSB is fraction

The most significant 4 bits of the LSB are used for 12bit precision.

MSB 0011001
25C +
Total = 25.75C
LSB 1100000
12/16=.75
Given: 0xE6 0x78

Note: negative due to the 8th bit of the MSB being 1

MSB 11100110
(NOT 11100110) +1
00011001 + 1
00011010
-26C +
Total = -25.0625C
LSB 1111000

15/16=.9375

0.9375

 

Click for full size

 

Testing MCP9808 with Bus Pirate

Filed under: Contextual Electronics — Brooke @ 3:55 pm

As part of the CE Header project from the CE Skills course , I picked an additional temp sensor to test with, the MCP9808.  I used a Bus Pirate (Dangerous Prototypes) and probes, from Seeed Studio, to iteratively poke at it until I understood how to talk to it via I2C.

Once I soldered the MCP9808 to a small carrier board from Adafruit, I placed it on a breadboard and wired it up to the Bus Pirate.  Please note, the cable and connectors in the image below are from the Seeed probe cable.  Some of the other probe cables have the colors in a different order on the connectors.

I used putty to connect to the Bus Pirate via a mini usb cable.

Command What it does
Initalize the Bus Pirate
m 4 1 Mode, I2C, Speed 5khz
W Turn power on
P Turn on pull ups

 

Command What it does Output
Find the I2C address
(1) Find the slave address 0x30(0x18 W) 0x31(0x18 R)

 

Command What it does Output
Working with the Config register
[ 0x30 0x01 [ 0x31 r:2 ] Read the register 0x00 (default)
[ 0x30 0x01 0x00 0x08 ] Enable Alert Stat
[ 0x30 0x01 0x00 0x08 [ 0x31 r:2 ] Enable Alert Stat and read back current config  0x00 0x08

 

 

Command What it does Output
Working with the Manufacturer register
[ 0x30 0x06 [ 0x31 r:2 ] Read the register 0x00 0x54  (default)

 

Command What it does Output
Working with the Device register
[ 0x30 0x07 [ 0x31 r:2 ] Read the register 0x04 0x00  (default)

 

Command What it does Output
Working with the Resolution register
[ 0x30 0x08 [ 0x31 r:1] Read the register 0x03  (default)
[ 0x30 0x08 0x00 [ 0x31 r:1] Set register to 0x00 or 1 bit resolution and read back 0x03

 

Command What it does Output
Working with the Ambient temperature register
[ 0x30 0x05 [ 0x31 r:2 ] Read the register ex: 0xC1 0xBC

Celsius = (C1BC & FFF)/16 = 24C or 75F, see P25 of MCP9808 Datasheet

Special result values

0x80 0x00, TA>TCRIT
0x40 0x00, TA>TUPPER
0x20 0x00, TA<TLOWER
0x10 0xBE ( after upper&1F ), TA < 0C, Celsius = d256 – ((( 10 & 0F ) * d16) + (BE/d16))= -245?

 

Click image for full size

 

Older Posts »

Powered by WordPress