P4 Windows Explorer Integration Not Connecting to the Correct Workspace

A client uses Perforce. The P4EXP (Windows Explorer integration tool) was not picking up the correct workspace. The pop-up menu reports, “no workspace has been set for this connection”.

Vijay Kudva has a page describing how to configure this.

The problem is that P4EXP ignores p4v’s configuration. You can configure P4EXP from the command line. The commands are:

p4 set P4CLIENT=<P4 workspace name>
p4 set P4PORT=<P4 Server IP:Port>
p4 set P4USER=<P4 User Name>

For example,

p4 set P4CLIENT=jk_workspace
p4 set P4PORT=192.168.1.2:1999
p4 set P4USER=james_knowles

Posted in Computer | Tagged , , , , , , | Leave a comment

How to Install gcc 4.7 on Mac OS X

XCode installs gcc 4.2 which has some bugs that prevent me from running skeinforge. This is how I installed gcc 4.7.

First install MacPorts. Then use the port command to install and activate the new gcc.

 sudo port install gcc47
 sudo port select gcc mp-gcc47
 hash gcc
 

To make the previous gcc active, use

 sudo port select gcc none
 hash gcc
 
Posted in Computer, Mac, Programming | Tagged , , , , | Leave a comment

3D Printing Lesson #1 — Buy a Kit

We’re in a place where a 3D printer is pretty much a necessity. We considered outsourcing, buying, and building. If you just need to print stuff, buy or outsource. For me, I also want the technical knowledge, so we settled on build, knowing this entailed a potentially long and painful process.

Sourcing your own parts is a very educational process, and I’m not sorry that we’re doing it this way, but if you’re going to build a printer, think long and hard before you decide to not buy a kit. Self-sourcing can be expensive, aggravating, and time-consuming.

Posted in 3D Printing | Tagged , , , , | Leave a comment

GPS Resources

These are various notes about working with GPS.

Summary

GPS is a bit of mess. ESR has a great summary of the problems in his article Why GPSes suck, and what to do about it, which includes a good overview of gpsd. An overview of what’s going on is on ESR’S Guide to Hacking with GPS.

Startup Time

I was initially caught off guard by the amount of settle time for a GPS unit. Under worst conditions, it can take upwards of 29 minutes for a complete download of the almanac if you just barely missed the last window.

NMEA Strings

ESR has a beautiful reference in NMEA Revealed.

 

Posted in Programming | Tagged | Leave a comment

5V to 3.3V Logic Level Shifting Stragety Notes

Here are some notes on different level-shifting strategies to convert from 5V to 3.3V circuits. As usual, this is for quick-and-dirty stuff.

I searched the Internet, found a couple of appealing strategies, and tried them out. I connected them to an Arduino output that cycled between high and low, and connected an oscilloscope to the output.

Strategy 1: Ordinary Diode

strategy1

This is a very simple strategy with few parts that I found on Rob Faludi’s page XBee Level Shifting.  This is what I saw on the scope:

DS1ET145103448_1

It’s been too many years since I’ve been in school to remember my analogue electronics, so at first this surprised me. Top to bottom is approximately 3.3V, but the huge rise and fall times were not what I expected.

I suspected that the 10k resistor was the culprit, (e.g. see Effects of Varying I2C Pull-Up Resistors), and threw in a 220 ohm resistor as an opposite extreme. The results were much more promising. The falling edge is very sloppy, but the rising edge is pretty crisp.

normal-diode-02-zoom

Strategy #2: Zener Diode

This is a variation on the first, but relying on the zener to limit voltage to 3.3V. The 10k ohm resistor I found on more than one site, so I tried it first of all.

strategy1

This produced the following on the scope:

DS1ET145103448_3

This is atrocious with a 10k resistor in there. Switching to the other extreme, the 220 ohm resistor, I got the following beautiful display. The falling edge has some roundoff on the bottom, but it demonstrates that the zener diode’s a viable quick and dirty level shifter.

DS1ET145103448_4

Strategy 3: Bus Transceiver

The last strategy I tried uses a 74LVC245 bus transceiver.

strategy1

Using an actual IC is a little heavy-handed for a single line, but the results were solid.

DS1ET145103448_5

Strategy #4: Resistor Voltage Divider

Because 3.3V is 2/3 of 5V, it’s easy to create a voltage divider out of resistors.

strategy1

Using 10k resistors produced the familiar shape:

DS1ET145103448_00

While dropping down to the other extreme, 200 ohms, produced a solid waveform:

DS1ET145103448_0

Demonstrating that if you need a dirt simple level shifter, three resistors may do in a pinch.

Updates

2013-02-14
Uploaded cleaner images, added fourth strategy.
Posted in Micro & Hardware | Tagged , | Leave a comment

Installing Rigol DS 1052E Ultrascope Software on Windows 7

The software that comes on CD in useless. The following steps seemed to be the pieces that worked. However, I’m not entirely sure since the entire experience was a bit of a hairball.

  • Go to the National Instruments website and install the latest VISA installer. (At the time of writing is version 5.3.)
  • Go to the Rigol website and install the UltraSigma software. I’m not sure this is needed. However, if will show whether the oscilloscope is recognized.
  • Go to the Rigol website and install the Ultrascope for DS1000E series software.
Posted in Micro & Hardware | Tagged , , , , | Leave a comment

Component Testing with an Oscilloscope

A nice short video introducing component testing with an oscilloscope (an “octopus”).

Posted in Micro & Hardware | Tagged , , , | Leave a comment

Fixing Mountain Lion Runaway parentalcontrolsd

We upgraded a machine to Mountain Lion (10.8.2), but found that parentalcontrolsd was running constantly with high CPU usage. The steps to correct the problem were found on the Apple Support Forums.

  1. Disable parental controls on all users.
  2. Delete the folder /Library/Application Support/Apple/ParentalControls
    Please note that this command is a little dangerous.
    $ sudo rm -rf "/Library/Application Support/Apple/ParentalControls"
  3. Restart Mac.
  4. Enable parental controls again.
Posted in SysAdmin | Tagged , , , | 3 Comments

Effects of Varying I²C Pull-Up Resistors

Effects of Varying I²C Pull-Up Resistors is a great article on a problem with the current Arduino I²C library (enabling internal pull-ups), and demonstrations of the effect of various pull-up resistors. It’s very much worth the time.

 

Posted in Micro & Hardware | Tagged , , , | Leave a comment

Communication Between Arduinos Using I²C

There are many great resources for describing what I²C is, and how to read data from an I²C device with the Arduino. However, I couldn’t find any suitable page for how to use I²C for communication between two Arduinos. This is for version 1.0.3.

Hardware

The hardware setup is the same as any other I²C setup. Connect each Arduino’s A4 inputs to each other, and connect the A5 inputs together. They will need a pull-up resistor, however the Wire library enables the internal pull-up resistors when begin() is called.

This may be adequate for your uses, but as is discussed in Effects of Varying I²C Pull-Up Resistors, it’s a case of YMMV. If internal pull-up resistors do cause a problem, then you’ll have to comment out the following lines from the Wire/utility/twi.c soruce file.

// activate internal pullups for twi.
digitalWrite(SDA, 1);
digitalWrite(SCL, 1);

Software Overview

The structure of the master code and the slave code are very different, but neither is complicated. Because I²C does not define a data protocol, you’ll have to roll your own. It’s common to use a model where devices are manipulated through writing to registers, and reading values back.

The Master

The master’s code is synchronous, and wraps its communication between beginTransmission() and endTransmission() calls. It sends with the write() methods, and receives with the requestFrom() method.

Setup

Setup requires only one command, begin().

void setup()
{
  // Start I²C bus as master
  Wire.begin();
}

Sending Data to a Slave

Sending data to a slave is done either by individual bytes, or in bulk. Here is a somewhat contrived example that sends the value of an analogue input pin to a slave every second. It writes bytes one at a time rather than using a buffer.

void loop()
{
  int input = analogRead(AnalogueInputPin);

  // Send two bytes to slave.
  Wire.beginTransmission(SlaveDeviceId);
  Wire.write(input >> 8);
  Wire.write(input & 255);
  Wire.endTransmission();

  delay(1000);
}

Receiving Data from a Slave

Receiving data from a slave is done either by individual bytes, or in bulk. Here is another contrived example that receives the value in the prior section.

void loop()
{
  // Request data from slave.
  Wire.beginTransmission(SlaveDeviceId);
  int available = Wire.requestFrom(SlaveDeviceId, (uint8_t)2);

  if(available == 2)
  {
    int receivedValue = Wire.read() << 8 | Wire.read();
    Serial.println(receivedValue);
  }
  else
  {
    Serial.print("Unexpected number of bytes received: ");
    Serial.println(available);
  }

  Wire.endTransmission();

  delay(1000);
}

The Slave

The slave controller uses asynchronous callback functions for its communication. Slave mode is strictly reactionary — it receives or sends data only at the best of the master. The callbacks are set in the setup() function, the loop() function is empty, and everything happens in the callbacks.

Setup

Setup requires two commands. The first is to call begin() with the slave’s ID number.

const byte SlaveDeviceId = 1;

void setup()
{
  // Start I²C bus as a slave
  Wire.begin(SlaveDeviceId);
...

The second is to set up the callbacks. Details are below.

Receiving Data from the Master

Data coming in to the slave from the master is handled in a single callback of the form

void callbackName(int numberOfBytesBeingTransmitted)

This is registered in the setup() function by calling the onReceive() method.

#include

const byte SlaveDeviceId = 1;

void setup()
{
  // Start I²C bus as a slave
  Wire.begin(SlaveDeviceId);
  // Set the callback to call when data is received.
  Wire.onReceive(receiveCallback);

  // For demonstration purposes.
  Serial.begin(9600);
}

void loop()
{
}

// aCount is the number of bytes received.
void receiveCallback(int aCount)
{
  if(aCount == 2)
  {
    int receivedValue  = Wire.read() << 8;
    receivedValue |= Wire.read();
    Serial.println(receivedValue);
  }
  else
  {
    Serial.print("Unexpected number of bytes received: ");
    Serial.println(aCount);
  }
}

Sending Data to the Master

Sending data to the master is also done asynchronously using a callback. When a request for data is received from a master, a callback is invoked. The callback must compose its reply in a buffer, then send the buffer all at once with a single call to write(). Note that the Write class performs no buffering for outgoing transmissions; any call to write() transmits the entire reply immediately.

Data coming in to the slave from the master is handled in a single callback of the form

void callbackName()

This is registered in the setup() function by calling the onRequest() method.

#include

const byte AnalogueInputPin = 0;
const byte SlaveDeviceId = 1;

void setup()
{
  // Start I²C bus as a slave
  Wire.begin(SlaveDeviceId);
  // Set the callback to call when data is requested.
  Wire.onRequest(requestCallback);
}

void loop()
{
}

void requestCallback()
{
  // Contrived example - transmit a value from an analogue pin.
  int input = analogRead(AnalogueInputPin);

  // To send multiple bytes from the slave,
  // you have to fill your own buffer and send it all at once.
  uint8_t buffer[2];
  buffer[0] = input >> 8;
  buffer[1] = input & 0xff;
  Wire.write(buffer, 2);
}

Sending and Receiving on the Same Slave

A single slave can both send and receive data by registering two callbacks. The appropriate callback is invoked automatically.

void setup()
{
  Wire.begin(SlaveDeviceId);
  Wire.onReceive(receiveCallback);
  Wire.onRequest(requestCallback);
}

“Gotchas”

The Wire library provides a convenient high-level wrapper for I²C. It has some oddities that will cause trouble if you’re not aware of them. Here are some gotchas.

Small Buffer

The Wire object‘s internal buffer is fixed at 32 bytes. You cannot send larger packets without modifying the library.

Asymmetric Behaviour

The write() method’s behaviour is different depending on whether the class is a master or a slave. See the sections on master and slave for details.

Type Coercion

The requestFrom() method’s overloads may confuse the compiler. If you get compiler errors, try coercing the parameters, for example:

const byte SlaveDeviceId = 1;
...
// Request data from slave.
Wire.beginTransmission(SlaveDeviceId);
int bytesReceived = Wire.requestFrom(SlaveDeviceId, (uint8_t)2);

No Clock Stretching

The current version of the library does not support clock stretching.

Collisions Between Multiple Masters

I’m still looking into this more, but it appears that there is no mechanism for a master to wait for for a busy bus to clear. The transmission simply fails.

Code

I put some some demonstration code on GitHub.

Updates

16 Feb 2013
Update pull-up resistor information. Update “gotchas” section.
Posted in Micro & Hardware | Tagged , , , , , , , , | Leave a comment