Paul Thomsen – Technology & Science

my thoughts on science and (mostly) computer-related technologies and technologies other than computer management

Astronomy: “The Universe” TV Series (from the History Channel) December 31, 2010

Filed under: Uncategorized — Paul Thomsen @ 12:52 pm

Over the last couple of years one of my main interests has been astronomy. It’s a huge field that could be approached in many ways. For now I’ve been trying to learn the key points and that has been very helpful in filling out my philosophical perspective on life.

One easy way to learn about astronomy is to watch the various TV shows available on the ‘knowledge’ channels. However they are generally very basic and often dated (astronomy is a field that has made amazing advancements in the last decade or two). The one series that has impressed me is “The Universe” as shown on The History Channel. It started in 2007 and strikes a reasonable balance between entertainment and science. I purchased the first 4 seasons and am slowly making my way through them.

I will caution that the series is often very sensationalist. I suppose that’s done for the ratings. Those of us that like our science to be serious have to be patient – it’s the price for getting an overview in an easy to consume form (TV). 

Here’s some notes, in case you’re interested:

Season One – Disc 1

Secrets of the Sun

  • The episode goes into a lot of the mechanics of the Sun but also includes lots of scary scenarios. And I doubt any of the details are “secrets”, other than to ancient man.
  • It’s a yellow dwarf, 1 million times the size of the earth
  • In 1 second the sun produces as much energy as humanity has used in all of our history
  • Photons takes hundreds of thousands to millions of years to get here, including 10 days on the outer layer and 8 minutes to cross space
  • The sun can only produce elements up to iron (the rest have come from other astronomical sources) 

The End of the Earth

  • Lots of sensationalist graphics and scenarios, as you probably expect, often repeated before and after the commercial breaks though there are no such breaks in the DVD
  • Some interesting details about near earth object and the history of the solar system

Season One – Disc 2

Alien Galaxies

  • This one is all about galaxies, which are admittedly simply amazing, but there’s nothing alien about them
  • The universe is 13.6 billion years old and the Earth is 4 billion years old, so much of what we see is from before when the earth was created
  • Galaxies around generally about 100 billion stars, all very far from each other
  • If the Sun is a dot of an “i” on a page, and then size of the Milky Way would be the size of the USA
  • Examples are Sombrero, M51, Centaurus , Andromeda, and most are very old
  • There a great but quick video of flying along the Grand Canyon
  • Galaxy types are: spiral, elliptical, and irregular
  • The uniformity of the expanding universe means we can’t tell where the center is
  • There are maybe 30 galaxies in our local group
  • Small and Large Magellanic clouds are galaxies that are visible without a telescope
  • Adaptive optics give ground-based telescopes good detail

Season 2 – Disc 4

Gravity

  • Gravity is the most universal of forces – it works at all scales
  • Things fall at the same rate, regardless of mass (of course)
  • They tried to do a roller coaster demo but the wind didn’t cooperate and so it was really useless
  • Traveling through the Earth between any two points would always take 42 minutes, by the straight path
  • Time/space is gravity, by definition
  • 97 miles per second is earth’s escape velocity
  • Potential energy vs. kinetic energy
  • Those zero-G flights are detailed at http://zerog.com, but are $5k
  • Einstein: acceleration = gravity (as in e=mcc)
  • But weight varies depending on the size of the masses involve – why is that? Mars vs. Earth. They didn’t really clarify that
  • They said “gravitational  waves are just like oceans waves”, but they aren’t because ocean waves are 2D and gravity waves are 3D
  • The LIGO labs are attempting to detect gravity waves, including one at Hanford here in Washington state: http://www.ligo-wa.caltech.edu/

Biggest Things

  • Earth is 100 million billion times smaller than the biggest stuff
  • The cosmic web is the biggest thing but not gravitationally bound
  • Galaxy super clusters are the largest entities. Shapley Supercluster is the largest (4k times size of Milky Way) or more
  • We’re in the Local Group and then the Virgo Supercluster
  • Other huge structures:
    • Boötes Void. Large but very little there
    • Lyman-alpha blobs (early galaxies?)
    • The largest galaxies, but what is the limit of a galaxy? Cluster diffused (CD) are often 10 to 20 Milky Way size (for example IC1101 is 60 times the size)
    • Radio Lobe galaxies are huge in mass
    • Hyper-giant stars
  • Black holes are common amongst galaxies
 

Why program electronics from Windows? November 21, 2010

Filed under: Uncategorized — Paul Thomsen @ 11:14 pm

That’s a fair question – if you need a device with certain features then chances are you can buy it. The Windows market is huge and thus practically everything has been addressed by some vendor, or soon will be. But there are a few counter-arguments:

  • it’s fun and a good way to learn programming, but a challenge can be to find fun things to program. The world is full of games, web apps, gadgets, etc. so you can easily search for something that will almost certainly do a better job of whatever you might try to program. So it’s hard to feel ‘instant gratification’ in the sense of doing something new from normal programming efforts. But if your program controls something physical, like an external display, accelerometer, other sensor, or robot, you really feel like you’ve done something special
  • for reasons beyond this blog, most computers don’t include sensors or other hardware that even smartphones have. So you might feel like you’re PC is missing out even though it’s amazingly easier to use and more powerful. So why not supplement your hardware and program the PC to use that supplemental hardware?
  • you might invent something useful! To start with you’ll be pleased to toggle an LED, but you can soon evolve to more interesting things. Eventually you might combine an interesting set of sensors and/or displays and/or interfaces to do something actually practical. And since it works with Windows it can amplify the value of the great programs and scenarios that are used with Windows
  • electronics are amazingly powerful and cheap these days. You can do some cool stuff for very little cost
  • anyone can program a cute window, but how many programmers can get their programs to interact with the physical world?
  • if you love electronics and want to do sophisticated stuff with them you would normally have to use microcontrollers and microcontroller programming techniques. That’s great if you’re going to be an electronics engineer but otherwise you’ll spend most of your time slowly developing arcane skills that aren’t beneficial beyond your hobby. However, if you can program the electronics from Windows then you get all the benefits of the electronics but also learn lots of general-purpose Windows programming skills (in my case .NET Framework, related languages, WPF, Silverlight, etc.). So you’ve got skills that you can use at work or elsewhere as well.
 

Using the U421 to read temperatures from a DS1822 via 1-Wire

Filed under: sensors,U421 — Paul Thomsen @ 10:37 pm

Reading temperatures in your Windows C# program via a U421 USB interface is very easy if you’re using the DS1822 (or related) temperature sensor (which are digital and 1-Wire based).

The biggest challenge I had was orienting the pins correctly. The pin-out in the datasheet was from the bottom perspective but I was reading it from the top perspective and thus got it wrong. The bad news is that it gets VERY hot that way; the good news is that it doesn’t burn out (at least as long as you catch that issue within a few seconds).

My code (as follows, and poorly formatted, I know), gives the core details in C#. My previous posts on the U421 apply as well, of course. I haven’t confirmed the calibration (-1.0) beyond very limited testing, so be sure to do your own calibration.

// get the ROM details (at least to confirm the sensor is responding)
                buffer[0] = 0x06;                      // whichever port it’s on – see the U421 documentation for details
                USBm.USBm_Reset1Wire(Device, buffer);  // open it, essentially
                present = buffer[1]==0;                // 1=not present, 0=present
                USBm.USBm_Write1Wire(Device, 0x33);          // read ROM
                USBm.USBm_Read1Wire(Device, buffer);         // the first byte is the sensor type
                sensor_type = buffer[1];
                for (int i = 1; i < 7; i++)                  // then the ROM address
                {
                    USBm.USBm_Read1Wire(Device, buffer);
                    ROM = ROM + buffer[1].ToString(“X2”);
                }
                USBm.USBm_Read1Wire(Device, buffer);         // and the CRC, if you want to confirm everything was sent properly
                CRC = buffer[1];

                // get the temperature
                buffer[0] = 0x06; // the buffer is written to by the reset, so we have to set it back to the right port again, even if we were to use a separate buffer
                USBm.USBm_Reset1Wire(Device, buffer);
                USBm.USBm_Write1Wire(Device, 0xCC);  // i.e. use any 1-wire device (even though we do have the ROM number)
                USBm.USBm_Write1Wire(Device, 0x44);  // tell it to get the temperature

                // read the temperature
                buffer[0] = 0x06;
                USBm.USBm_Reset1Wire(Device, buffer);
                USBm.USBm_Write1Wire(Device, 0xCC); 
                USBm.USBm_Write1Wire(Device, 0xBE);  // read the temperature into the scratchpad – the first two bytes in particular
                USBm.USBm_Read1Wire(Device, buffer);
                byte1 = buffer[1];
                USBm.USBm_Read1Wire(Device, buffer);
                byte2 = (byte)((int)buffer[1] & 0x07);
            }
            celcius = Math.Round( ( (byte1 + (byte2 * 256)) / 16.0 ) – 1.0, 1);  // the “16.0” is dependent on the granularity – the 1.0 is based on calibration with physical thermometers (and feeling)
            farenheit = Math.Round( (celcius * 1.8) + 32, 1);          // the standard conversion algorithm

 

The importance of locking your U421 while using timed events November 15, 2010

Filed under: programming,U421 — Paul Thomsen @ 9:56 pm

My U421’s have been working well for me but as my solutions got more sophisticated they got less reliable. In particular, I was outputting to an LCD, outputting to an LED, and checking (inputting from) a switch at the same time (using multiple timers). But at seemingly random times my application would crash. It makes sense that I should only do one thing with the device at a time, but all my solutions failed.

I tried suspending the conflicting timers as operations were done, but that only partially helped. Setting a global variable didn’t help at all. Toggling only the relevant bits (“WriteABit”) didn’t help either.

Of course I didn’t expect I was the first person to hit such an issue so I did some research and found that the solution for C# (and similar languages, I assume) is to use locks – an old concept for anyone using database servers, clusters, or other complex systems.

In particular, I changed my code to create a generic object:

object U421_lock = new object();

and then later whenever doing anything U421 related I wrapped the code with:

lock( U421_lock )
{
       // do stuff
}

 

What devices do we need? October 10, 2010

Filed under: devices — Paul Thomsen @ 10:35 pm

These days the technology news seems to be all about “devices”. This is my summary of what “devices” mean.

The possibilities (in no particular order):

  1. phone – real-time communication
  2. media player, for entertainment on the go – music, podcasts, video, streaming (live) video, TV, radio (or some subset of these)
  3. camera / video camera (of sufficient quality for normal needs)
  4. very portable computer/PDA, especially for web browsing, web apps, texting/IM, simple tools (e-mail,calendar,notes,calculator,etc.), and games
  5. smartphone, meaning serving the need of phone, media player, portable computer/PDA, and probably camera all in one
  6. full-power computer – for complex input/output (including full keyboard, separate mouse, and multiple monitors), full power for complex applications, expandability
  7. server – common storage for media, backup of content and application sources, easy access to common devices (printer/scanner), virtual machine support (important only for techies), etc.
  8. laptop computer – for complex input, better output, nearly full power, optical media device player 
  9. walk-around computer (tablet/slate) – easy input/output for meetings, note taking, checklists, etc.
  10. handy computers (netbook) – by the TV, bed, etc. for impromptu computing without constantly bringing the others with you
  11. gaming console / media console – for easy-to-use, full power gaming, with related applications such as video and audio streaming
  12. GPS – location, route finding
  13. DVR (digital video recorder)
  14. related devices: watch/clock, alarm clock, flashlight, sound recorder (audio notes), pointer, projector controller, remote control(s)
  15. other alternatives: portable TV, portable DVD player, e-reader

Then there’s the question of implementation details:

  • instant on (use it now) – this is especially important for quick-use devices, as in mobile devices
  • input – keyboard, mouse, touch, stylus, voice, as appropriate to the task and environment
  • operating system (ease of use and support of powerful applications (as needed))
  • cross-device support (content, etc. is available on alternate devices depending on scenario)
  • size (easy to see, easy (enough) to carry, easy to find, not too big)
  • weight (easy to carry)
  • battery life (so you don’t have to worry about recharging all the time) – multiple devices help to address this by each having their own batteries, but that’s a weak reason to have multiple devices
  • robust (can withstand a fall or other common hazards)
  • home vs. work vs. car – portable device or dedicated to each environment? Work computer may have some high power applications, and be particularly secure, for example
  • ecosystem – the stuff that goes with the device to make it hum, often by third parties. This can be software, if the device is ‘smart’, and hardware. Even training, user self-support web sites, content, etc. can be critical

What are my solutions to each:

  1. phone: Win7 phone (when available)
  2. media player: Win7 phone, I hope, but supplemented with iPod Touch (only because I wanted it for device 4 below), Sony Walkman (radio), and old Zune (FM radio and other media)
  3. camera: Win7 phone, supplemented by iPod Touch
  4. very portable computer: Win7 phone, supplemented by iPod Touch (different app store)
  5. smartphone: Win7 phone
  6. full-power computer: 1 each at work and home, with 4 monitors at work and 3 monitors at home
  7. server: plenty at work, but none at home (yet?) – the full-power computer largely serves this purpose
  8. laptop computer: traditional Toshiba Tecra M5 (from work)
  9. walk-around computer: <waiting> I have to agree that the iPad is the only great solution for consumers in this space at this time, but there are good alternatives for work scenarios, and the iPod Touch is close enough for me until the many competitors become available (spring 2011?)
  10. handy computers (netbook): <waiting>, but may start with one soon?… The sector has disappointed me. Users seem to think of them as cheap laptops and vendors haven’t lead the way (they’ve largely just agreed with the users). There’s an opportunity here…
  11. gaming console / media console: XBOX 360 (multiple)
  12. GPS: <none yet>, but maybe the Win7 phone will help in this regard. As a mountaineer, I do have a serious need here 
  13. DVR: dedicated DVR and a Win7 Media Center PC (but it’s not HD capable)
  14. related devices: Win7 phone for most of these (but not flashlight?)
  15. other alternatives: I don’t do these enough to have standalone devices for these purposes

Of course one problem with the above lists is that they’re too long. That works against simplicity and discourages bringing each along so that it’s actually there when you need it. Fortunately the smartphone does a good job of consolidation, so you can probably drop about 4 other devices off the lists (devices 1, 2, 3, most of 14, and maybe 12). The ‘handy computers’/netbooks, at least in my vision, also minimize the multi-device issue in that they’re supposed to be left where you need them. And unsophisticated users are not going to worry about servers, and can often make do with a laptop rather than a full-power PC. Walk-around computers are certainly an unproven need for almost all users. Most people could make do with a simple GPS or none at all.

So what do real people really need:?

  • smartphone
  • laptop
  • gaming console / media center
  • DVR

People that aren’t into gaming and/or good TV could do without the latter two, in which case a smartphone and laptop would be enough. In so doing they’re not embracing the wonderfulness of the digital age, but that is their privilege – diversity is good. Should we encourage them to embrace more? Someday maybe those two will enough for all of us, in that they will incorporate all the other devices. But IMHO the two will never embrace each other – small screen and large screen(s) are necessarily fundamentally different, unless an in-brain interface can be produced.

Have I missed any devices or needs?

p.s. I’m not mentioning network devices, monitors, TVs, extra disks, printers, optical media players, electronic picture frames, Bluetooth headsets, or I/O devices, which I think of as infrastructure and outside of the scope of this discussion.

 

Getting started using LCD displays from a Windows PC using the U421

Filed under: electronics,programming,U421 — Paul Thomsen @ 10:30 pm

Full function monitors are admittedly cheap these days (roughly $100 on the low end), so using an LCD display from a PC has little value. But you can build an LCD solution for $60 and the information on it will be visible even when your screensaver is active or the machine is locked. They also allow you to more immediately focus on the information you display on them (as opposed to the multiple windows on your monitors).

Assuming you have a need to use an LCD display from your Windows PC, here’s a solution that will work:

The strength of the U421 in this case is that it has LCD APIs, so you don’t have to worry about the subtleties of timing the data transfer and coordinating RS, R/W, and E.

The wiring is fairly simple:

  • B data lines to the LCD data lines (i.e. B0 to DB0, B1 to DB1, etc.)
  • A data lines to the RS/Rw/E lines (A0 to Rw, A1 to Rs, A2 to E)
  • power lines as appropriate, except nothing to VDD (unless you want to set up a control for contrast)

Preparation for the coding is:

  • copy the USBMicro USBm.dll into the bin\debug folder of the application
  • add “using System.Runtime.InteropServices” to the ‘using’ part of your code
  • add the public class USBm from the USBMicro sample code to your application

The key code is:

result = USBm.USBm_FindDevices();
Device = 0; // assuming there’s only one device
USBm.USBm_DirectionA(Device, 0xFF, 0xFF); // output only
USBm.USBm_DirectionB(Device, 0xFF, 0xFF);
result =
USBm.USBm_InitLCD(Device, 0x01, 0x12); // A.0 is the RW line, A.1 is the RS line; data port B, A.2 is the E line
result = USBm.USBm_LCDCmd(Device, 0x30 + 8); // function set: 8 bit; 2 lines, font 0
result = USBm.USBm_LCDCmd(Device, 0x04); // entry mode – not incrementing, in either direction
result = USBm.USBm_LCDCmd(Device, 0x0C); // display on; no cursor, no blinking
result = USBm.USBm_LCDCmd(Device, 0x01); // clear display

output[0] = “initialized”;
for (int i = 0; i < output[0].Length; i++)
    result =
USBm.USBm_LCDData(Device, Convert.ToByte(output[0][i]));

p.s. There’s a key difference between the LCD-20x4Y (black on green) and LCD-20x4BW (black on white) displays – the second line starts at a different DDRAM address. Use 64 rather than 40.

 

Using a combobox value in C#

Filed under: programming — Paul Thomsen @ 11:45 am

This is probably self evident to anyone that’s been programming in C# (and thus the .NET Framework) for any length of time, but for a newbie it’s harder than I would have expected.

I was expecting it be something like:

uint value;
value = (uint)combobox1.SelectedValue.Content;

Instead, it’s:

value = Convert.ToUint32( ((ComboBoxItem)comboBox1.SelectedValue).Content.ToString() );

That’s non-trivial. So what does it mean:

  • cast the combBox1.SelectedValue, which is a generic object, to a ComboBoxItem object. Then you can use the Content property. This is the main trick, and be sure you get the parentheses right.
  • IntelliSense is not intelligent enough to show you the options for a cast object so you have to know that Content is an available property for a ComboBoxItem. That’s not hard to find but it would be nice if IntelliSense helped here – I suspect I’m going to have this problem with other UI objects.
  • But the Content property is an object itself, so you have to use the ToString() method to get the value.
  • There’s no ToUint method, so you have to use the Convert object’s ToUint32() method

p.s. What’s worse is that I couldn’t find a sample on the Internet, despite quite a lot of searching. There’s plenty of examples of adding values to a combobox or changing the style, but nothing this basic. I had to revert to using a book (egad!) and even then the sample code only indirectly clarified it.

 

Preparing your Netbook October 9, 2010

Filed under: devices — Paul Thomsen @ 6:01 am

Let’s face it, netbooks are small and slow. Otherwise why would anyone buy a real laptop, desktop, or server? Those form factors have their virtues. Netbooks have their virtues as well (small and cheap). So once you have one, you should optimize it for your use. Here’s what I do (I assume technical skills):

  1. set up accounts as you like, computer name, etc.
  2. install Windows Live so that you can use Mesh to remotely control it. Thus you can use a real keyboard and mouse from your main PCs to do the rest.
    1. most importantly, you can do other things while doing the following steps
  3. configure as you like (colors, taskbar, etc.), to make it friendly and comfortable
    1. maximizing screen space is especially important – it’s definitely limited. So consider options you might not normally use, such as hiding the task bar and reducing the application options that use screen space (e.g. use IE9)
  4. uninstall the crapware to improve performance. This one is important but takes awhile so it’s good to do the above first so you’re comfortable while doing this one
  5. install Microsoft Security Essentials or equivalent to make it secure
  6. install patches to really make it secure. This is the most time consuming step, but is one-time
  7. reviewing services probably won’t help in that there aren’t that many at this point and those that are there are needed and should be low impact
  8. clean up the Start, Programs folders, and maybe the disk, to finalize the cleanup
  9. now you can install/configure the stuff you actually want to use. But try to keep to the core stuff you would actually miss.

As to what you might want to install:

  1. IE9, for it’s display and load up efficiencies
  2. configure Windows Live as you prefer, including synching your IE favorites. That way you have all your personal e-mails, favorite web sites, files, etc. without having further effort
  3. install real Office for e-mail (Outlook)
  4. copy media, such as music, videos, podcasts, etc.
  5. to keep informed:
    1. an RSS reader, such as RSS bandit
    2. a Twitter reader, such as TweetDeck
  6. apps, such as games, to make it fun
    1. the only problem is that it is a netbook, so you might not want to include resource intensive apps such as World Wide Telescope
  7. download podcasts, music, etc.?…
    1. download iTunes, Zune, etc. as appropriate
    2. don’t make the netbook your home machine for the iPod, unless that really is your main machine (in which case we should talk…)

The issues that concern me are:

  • for whatever reason, some app developers don’t have Windows equivalents, such as Angry Birds, various businesses, my favorite science apps, news services such as BBC, games, etc.
  • non-standard keyboard, though that’s only an issue when I’m using it directly (non-remotely)

What I do love:

  • it’s Windows! like everything else I use (and no, I’m not just saying that because I work for Microsoft)
    • that’s mostly a familiarity issue, but also security in that Windows Update, Security Essentials, and similar resources are looking out for me
    • Office works
    • gadgets work
    • it has the latest Microsoft technologies, such as IE9
  • I can program it like any other Windows machine (though I admit that only applies to those of us that can program)
  • it’s very portable
  • battery life is not a problem, though I could always use more

p.s. If you need to rebuild your machine (with Win7, for example), you can do so via a USB

 

Getting electronics right (or not) May 31, 2010

Filed under: electronics — Paul Thomsen @ 8:43 pm
As stated earlier in this blog, I like the FT232R – it’s simple and yet flexible. But it turns out it does have limits. In particular, it seems it can’t drive what I would call ‘synchronous devices’ (or smart devices that require synchronization to work properly). An example is any kind of HD44780-driven LCD display.
 
More to the point is that for any kind of interesting electronics, a lot of things have to come together just right. Examples:
 
  • breadboard wiring – this might seem simple, but it’s easy to get the alignment wrong, especially if you’re connecting wire to wire on the breadboard
  • voltage – is VSS, VEE, VCC, or similar variances positive, negative, or ground? I’m sure professionals always know the answer, but what about the rest of us?
  • E, RS, R/W, etc. – which ones are important, what do they mean? To some degree it depends on what you’re doing – for example, are you doing any reading amongst the writing?
  • timing – should you toggle the data before or after E goes high (or low)? How soon before? How fast should the transition be made?
  • pull-down-resistors and grounding unused pins – how important are they? I’m not convinced on these two. They might help with the speed or cleanness of the transitions, but I haven’t seen the data or results to prove their importance. This is an open question for me.
  • programming commands (including sequence) – are they working or not? You know they’re working if the output is what you expect, but if you’re not getting the right output: is it the commands (or their sequence), or is it one of the above elements? Unlike traditional programming, you can’t (usually) run a debugger on the destination device to ensure the data is getting through
  • soldering, if need be

How to minimize these problems:

  • double and triple check the wiring, including using a magnifying glass, and ensure the wiring is properly aligned, vertically or horizontally
  • put LEDs in place of the circuit to ensure the lines at least get toggled as much as you expect, and in the patterns you expect (randomly, lots at the beginning of the command sequence, lots at the end, etc.)
  • try variations. This is easiest with the programming but can apply to the other points. Even if something surprising happens, that could be a clue as to what’s wrong
  • read the documentation carefully. On the other hand, don’t be surprised if there are errors. Most specs are relatively obscure documents that don’t go through a lot of professional editing or peer review
  • use a voltmeter to ensure that pins are isolated from each other as much as they should
 

On the importance of FT232 SetBitMode April 7, 2010

Filed under: electronics,FT232R — Paul Thomsen @ 9:30 pm

I had a nice working FT232 program that was doing well for days. I restarted it often, rewired, reconnected the device, etc. and it was working great. Then I came back a week later and it didn’t work! What could have happened? Loose wires would seem obvious, but that didn’t check out. Fried chip? I hoped not but swapped them out. Bad breadboard? That was a longshot but I was getting desperate. Forgotten last minute code change? I couldn’t see it. What could the issue be?

Strangely, other programs worked fine with the same or similar components. Then I minimalized the circuit and code and it still behaved strangely (wouldn’t even toggle a single bit). Finally it occurred to me that my code no longer set the bit mode before each write. At one point I had assumed that could be rarely done and the code would work, and maybe that would speed things a bit. And generally that seems to be true, as evidenced by my earlier experience. But under some circumstances (I’m not sure what, but something to do with running other programs, I suppose), this detail can become important.

So the conclusion is: to be safe, set the bit mode before your writes:

SM.bitBang_SetBitMode(ftHandle, 15, 0x1); // use the first 4 bits of the D bus