Multiple (4x) SPI device on rasberry pi 2 running windows 10 iot - raspberry-pi2

I had successfully communicate single SPI device (MCP3008). Is that possible running multiple (4x) SPI device on raspberry pi 2 with windows 10 iot?
I'm thinking to manually connect the CS(chip select) line and activate it before calling spi function and in-active it after done the spi function.
Can it be work on windows 10 iot?
How about configure the spi chip select pin? Change the pin number during the SPI initialization? Is that possible?
Any smarter way to use multiple (4 x MCP3008 ) SPI device on windows 10 iot?
(I'm planning to monitor 32 Analogue signal which will be input to my raspberry pi 2 running windows 10 iot)
Thanks a lot!

Of course you can use as many as you want (as many GPIO pins).
You just have to indicate the device to which you are calling.
First, set the configuration of the SPI for example, using chip select line 0
settings = new SpiConnectionSettings(0); //chip select line 0
settings.ClockFrequency = 1000000;
settings.Mode = SpiMode.Mode0;
String spiDeviceSelector = SpiDevice.GetDeviceSelector();
devices = await DeviceInformation.FindAllAsync(spiDeviceSelector);
_spi1 = await SpiDevice.FromIdAsync(devices[0].Id, settings);
You can not use this pin in further actions! So now you should configure the output ports using GpioPin class, which you will use to indicate the device.
GpioPin_19 = IoController.OpenPin(19);
GpioPin_19.Write(GpioPinValue.High);
GpioPin_19.SetDriveMode(GpioPinDriveMode.Output);
GpioPin_26 = IoController.OpenPin(26);
GpioPin_26.Write(GpioPinValue.High);
GpioPin_26.SetDriveMode(GpioPinDriveMode.Output);
GpioPin_13 = IoController.OpenPin(13);
GpioPin_13.Write(GpioPinValue.High);
GpioPin_13.SetDriveMode(GpioPinDriveMode.Output);
Always before transfer indicate device: (example method)
private byte[] TransferSpi(byte[] writeBuffer, byte ChipNo)
{
var readBuffer = new byte[writeBuffer.Length];
if (ChipNo == 1) GpioPin_19.Write(GpioPinValue.Low);
if (ChipNo == 2) GpioPin_26.Write(GpioPinValue.Low);
if (ChipNo == 3) GpioPin_13.Write(GpioPinValue.Low);
_spi1.TransferFullDuplex(writeBuffer, readBuffer);
if (ChipNo == 1) GpioPin_19.Write(GpioPinValue.High);
if (ChipNo == 2) GpioPin_26.Write(GpioPinValue.High);
if (ChipNo == 3) GpioPin_13.Write(GpioPinValue.High);
return readBuffer;
}

From: https://projects.drogon.net/understanding-spi-on-the-raspberry-pi/
The Raspberry Pi only implements master mode at this time and has 2 chip-select pins, so can control 2 SPI devices. (Although some devices have their own sub-addressing scheme so you can put more of them on the same bus)
I've successfully used 2 SPI devices in the DeviceTester project and Breathalyzer project within Jared Bienz's IoT Devices GitHub repo.
Notice, that in each project, the SPI interface descriptor is declared explicitly in the ControllerName property for the ADC and Display used in both of these projects. Detailed information around the Breathalyzer project can be found on my blog.
// ADC
// Create the manager
adcManager = new AdcProviderManager();
adcManager.Providers.Add(
new MCP3208()
{
ChipSelectLine = 0,
ControllerName = "SPI1",
});
// Get the well-known controller collection back
adcControllers = await adcManager.GetControllersAsync();
// Create the display
var disp = new ST7735()
{
ChipSelectLine = 0,
ClockFrequency = 40000000, // Attempt to run at 40 MHz
ControllerName = "SPI0",
DataCommandPin = gpioController.OpenPin(12),
DisplayType = ST7735DisplayType.RRed,
ResetPin = gpioController.OpenPin(16),
Orientation = DisplayOrientations.Portrait,
Width = 128,
Height = 160,
};

Related

Bacula multiple storage device

It seems to be relatively a simple question. I have two mount points on bacula-sd (storage) server- one for local drive and one for s3 bucket (off side backup) and what I need is start two concurrent job at the same time on both drives. So far I have something like that in bacula devices.conf
Device {
Name = "example.prod.com"
Device Type = File
Media Type = File
Archive Device = "/data/bacula/example.prod.com"
LabelMedia = yes
Random Access = yes
AutomaticMount = yes
RemovableMedia = no
AlwaysOpen = no
Maximum Network Buffer Size = 65536
}
Device {
Name = example.prod.com-s3
Device Type = File
Media Type = File
Archive Device = "/mnt/bacula-backup-storage/example.prod.com-s3"
LabelMedia = yes
Random Access = Yes
AutomaticMount = yes
RemovableMedia = no
AlwaysOpen = no
Maximum Network Buffer Size = 65536
}
but it's probably not enough because the job started only on the first device. Do I need disk autochanger or something?
You have to change Media Type = ... parameter to be different for both Devices, i.e.
Device {
Name = "example.prod.com"
Device Type = File
Media Type = File
...
}
Device {
Name = example.prod.com-s3
Device Type = File
Media Type = S3
...
}
It won't work otherwise.

Output audio to speaker and headset at the same time?

I'm using NAudio to output audio files to both the speaker and a headset on a window 10 laptop. I created two WaveOut and assigned the corresponding device number. But I cannot here the audio from the speaker when the headset is plugged in. Can anyone let me know how to solve this? Here's my code (it works fine on the headset or the speaker separately, but I want to hear the sound from both of them at the same time):
var input1 = new Mp3FileReader(PATH + "left.mp3");
var input2 = new Mp3FileReader(PATH + "right.mp3");
var waveProvider = new MultiplexingWaveProvider(new IWaveProvider[] { input1, input2 }, 2);
var input3 = new Mp3FileReader(PATH + "left.mp3");
int channel = ((Mp3FileReader)input1).Mp3WaveFormat.Channels;
Debug.WriteLine(channel);
waveProvider.ConnectInputToOutput(0, 0);
waveProvider.ConnectInputToOutput(3, 1);
WaveOut wave = new WaveOut();
wave.DeviceNumber = 1;
wave.Init(waveProvider);
WaveOut wave1 = new WaveOut();
wave1.DeviceNumber = 0;
wave1.Init(input3);
wave.Play();
wave1.Play();
I think the issue is that you don't have two soundcards, you have one soundcard that is switching between playing sound out of the speakers and headphones. If you bought a USB headset then you'd have two soundcards, and should be able to play different sounds through each one separately.

Send and Receive MIDI with Swift and CoreMIDI

I'm not very familiar with Swift/Objective-C or the Cocoa environment and I've been having a lot of trouble figuring out how to send or listen for data from a USB device with CoreMIDI. I'm trying to send the message (144, 36, 5) to my MIDI controller (an Ableton Push) which I have accomplished before using the Bitwig Studio Scripting API. I haven't been able to find much on this other than Apple's docs and they haven't been particularly helpful for me. So far I've figured out how to get a list of devices and check out their names, but beyond that I'm stuck.
What I've written so far trying to send MIDI:
var pushDevice = MIDIGetDevice(2)
var secondEntity = MIDIDeviceGetEntity(pushDevice, 1)
var pushDestination = MIDIEntityGetDestination(secondEntity, 0)
var midiPort = MIDIPortRef()
let myData : [Byte] = [ Byte(144), Byte(36), Byte(5) ]
var packet = UnsafeMutablePointer<MIDIPacket>.alloc(1)
var pkList = UnsafeMutablePointer<MIDIPacketList>.alloc(1)
packet = MIDIPacketListInit(pkList)
packet = MIDIPacketListAdd(pkList, 1024, packet, 0, 3, myData)
MIDISend(midiPort, pushDestination, pkList)
I feel like a bit of a goof for not being able to figure this out, I imagine it has to be a simple solution that I'm just not able to figure out for some reason. I don't think I'm properly constructing the MIDIPacketList or the MIDIPort, and I have no idea how to go about creating a callback and listening for MIDI messages.
I figured out how to send MIDI data by grabbing the device via it's unique ID. I'm not sure how memory management works in Swift, so keep that in mind. I will check back in later if I figure out how to properly create a callback and listen for MIDI input.
import Foundation
import CoreMIDI
var midiClient = MIDIClientRef()
var result = MIDIClientCreate("Foo Client", nil, nil, &midiClient)
var outputPort = MIDIPortRef()
result = MIDIOutputPortCreate(midiClient, "Output", &outputPort);
var endPoint = MIDIObjectRef()
var foundObj = MIDIObjectType()
result = MIDIObjectFindByUniqueID(UNIQUE_ID, &endPoint, &foundObj)
var pkt = UnsafeMutablePointer<MIDIPacket>.alloc(1)
var pktList = UnsafeMutablePointer<MIDIPacketList>.alloc(1)
let midiData : [Byte] = [Byte(144), Byte(36), Byte(5)]
pkt = MIDIPacketListInit(pktList)
pkt = MIDIPacketListAdd(pktList, 1024, pkt, 0, 3, midiData)
MIDISend(outputPort, endPoint, pktList)

How to configure OLinuXino Lime UART's using DTB

How do I configure the UART's in the OLinuXino Lime using a DTB file? I'm using the image from http://eewiki.net/display/linuxonarm/A10-OLinuXino-LIME.
UART 0 is already configured. This is the relevant part from the DTS file, if I understand correctly:
uart0: serial#01c28000 {
pinctrl-names = "default";
pinctrl-0 = <&uart0_pins_a>;
status = "okay";
};
From http://linux-sunxi.org/Memory_map I can get the memory space for the other UART's. But where do I get the syntax for the pinctrl-0 field, for instance?
Can we configure the hardware with the DTB file only with no need for Allwinner's FEX file?
In an "ideal" situation, should the DTB files be configured by the hardware manufacturer or should they be configured by the developer (is there a manual)?
We can either use Allwinner's FEX file or Open Firmware's Device Tree (DT).
Add these lines to the DT source file (DTS) and compile with dtc.
uart2: serial#01c28800 {
pinctrl-names = "default";
pinctrl-0 = <&uart2_pins_a>;
status = "okay";
};

AutoIt DllCall to USB

I am having trouble with AutoIt's DLLCall.
I am trying to control a Delcom USB Indicator LED Light using AutoIT. To do this, I have a .dll which includes the following functions:
DelcomGetDeviceCount: returns the number of Delcom USB devices
DelcomGetNthDevice: searches for specified device type, gets string of device name
DelcomOpenDevice: takes device name and returns handle to the USB device
DelcomLEDControl: takes USB handle, sets state of the LED
Here is a link to the documentation on these DLL functions.
I think my problem is not formatting the pointer to the device name correctly, because my call to DelcomGetNthDevice returns 0, failure to find device, even though I detect one device using DelcomGetDeviceCount.
I have tried
Local $handleDLL = DLLOpen("C:\DelcomDLL.dll")
Local $stString = DllStructCreate("wchar Name[512]")
Local $devices = DllCall($handleDLL,"dword","DelcomGetDeviceCount","dword",0)
Local $result = DllCall($handleDLL,"dword","DelcomGetNthDevice","dword",1,"dword",0,"ptr",DllStructGetPtr($stString))
Local $handleUSB = DllCall($handleDLL,"handle","DelcomOpenDevice","str",DllStructGetData($stString,"Name"),"dword",0)
Local $result2 = DllCall($handleDLL,"dword","DelcomLEDControl","handle",$handleUSB[0],"dword",0,"dword",1)
MsgBox(0,"# of Devices",$devices[0])
MsgBox(0,"Bool Found Device",$result[0])
DllClose($handleDLL)
and
Local $handleDLL = DLLOpen("C:\Users\b46020\Documents\Asher Project\DelcomDLL.dll")
Local $stString
Local $devices = DllCall($handleDLL,"dword","DelcomGetDeviceCount","dword",0)
Local $result = DllCall($handleDLL,"dword","DelcomGetNthDevice","dword",1,"dword",0,"str*",$stString)
Local $handleUSB = DllCall($handleDLL,"handle","DelcomOpenDevice","str*",$stString,"dword",0)
Local $result2 = DllCall($handleDLL,"dword","DelcomLEDControl","handle",$handleUSB[0],"dword",0,"dword",1)
MsgBox(0,"# of Devices",$devices[0])
MsgBox(0,"Bool Found Device",$result[0])
DllClose($handleDLL)
but in each case I turn up 1 device but cannot get its name.
I would greatly appreciate your help.
Thanks,
Jonathan
Solved it:
Local $handleDLL = DllOpen("C:\DelcomDLL.dll")
$strName = DllStructCreate("char Name[512]")
$ptrName = DllStructGetPtr($strName)
Local $result = DllCall($handleDLL, "dword", "DelcomGetNthDevice", "dword", 0, "dword", 0, "ptr", $ptrName)
Local $handleUSB = DllCall($handleDLL, "handle", "DelcomOpenDevice", "str", DllStructGetData($strName, "Name"), "dword", 0)
Local $result2 = DllCall($handleDLL, "dword", "DelcomLEDControl", "handle", $handleUSB[0], "dword", $color, "dword", $state)
Local $closed = DllCall($handleDLL,"dword","DelcomCloseDevice","handle",$handleUSB[0])
DllClose($handleDLL)