How to use a MCP23017 with MCP3008 for I2C voltage sensor with Raspberry Pi? - linux

I would like to know if is possible to use an MCP23017 16 bit I/O expander with a MCP3008 ADC and read the voltage with a Raspberry Pi 2. I want to use the ADC as an I2C device. I would like to do this so I don't have to run the program a 'root', so I'm thinking that running the ADC as an I2C device will fix this problem. I'm looking for help with how to wire the system as well as programming it. I'm using the Python 3 editor. The existing program I have will be used to plot a sine wave generated by a AD9850 DDS module who's signal is amplified and fed into a device. I want to measure this voltage. I know how to use a voltage divider, but am having trouble coming up with a way to read it. The measured voltage value needs to be stored as global variable that can be passed around the program. Right now I'm mainly concerned with not running the program as a root, turning the ADC into an i2c device, and storing the voltage as a global variable to be passed around in an existing program.

I have not worked with any kind of I2C TO SPI converter. Still, you can use some I2C to SPI bridges if they work, I just googled it, but that can cause wiring problems.
I can suggest you the same ADC MCP series with I2C interface.Thus, the further I2C connections with MCP23017 expander and then the Raspberry pi would be easy.You can go through various analog to digital converters that can be I2C interfaced with their codes in python or java for pi like MCP3425, MCP3426, MCP3427, MCP3428. You can easily find them or also check control everything as that would be easy to interface using I2C cables and adapters preventing connection or wiring problems.For codes: https://github.com/ControlEverythingCommunity?utf8=%E2%9C%93&query=MCP34
The following codes for MCP_23017 can also help you code the way you want easily with expander being connected to pi:https://github.com/ControlEverythingCommunity/MCP23017_16-Channel.
I think this would solve your problem!!
Thanks.

Related

How to Disable Hardware SPI Chip Enable/Chip Select on Raspberry Pi?

I'm setting up a Raspberry Pi 4b with a number of Adafruit chips, and thus have used their CircuitPython library to control SPI communication. They've conveniently set up a way to use any GPIO pins as chip selects, but as a result I had no idea that there are two hardware chip selects on the Raspi (CE0 and CE1 on GPIO8 and GPIO7 respectively). I have already wired these pins (GPIO7&8) with the intention of using them as GPIO outputs, but I've noticed I GPIO8/CE0 is connected to the SPI clock.
Adafruit actually mentions that the NO_CS flag doesn't work in their documentation, and I can't seem to find anything useful online.
How can I disable the hardware CS pins? I know the SPI_NO_CS flag in SPI_MODE is already a bug in the spi-bcm library, and I found this patch, but I'm not sure if it would work (I think CircuitPython utilizes a hardware CS?), let alone how to apply it.

Recording wav file Using Arduino

I am bit stuck, how can I make my arduino record into .wav files?
The arduino is connected with a microphone, and am using the Arduino ADC.
Any ideas? Will I be able to play them back using my pc?
many question cross my head
1- Is this possible using an arduino Uno
2- Is this possile using just a microphone connected to the Arduino ADC
3- if yes how can i get the wav format.
The idea gonna be like this
Ardiuno microphone-->Uno ADC -->arduino (library making wav sound)--> Storing data to a an SD card connected via SPI or maybe (connecting a Raspberry as a storage device)
also another question:
4- Do I need an amplifier due to the act that analog output from the microphone is very weak so the ADC couldn't detect the variation
In another log i had seen that i should connect the microphone to a level shifter.And that cause of the analog output is AC so i have to make the negative wave as 0 (for 10 it ADC)
the zero point as 512 and the positive as 1024 (10 bit ADC).(really i'm not sure about this part)
doing some research i got this library "https://github.com/TMRh20/TMRpcm/wiki/Advanced-Features#recording-audio" which is supposed to do the job, I mean making some wav file from the analog input.
So any help would be appreciated
Thx in advance,
Salah Laaroussi
Yes, although a bit complex it is very possible to do this via an uno.
The biggest hurdles to overcome is the limited amount of RAM and the clock speed. You will have to setup twin buffers to handle writing to the SD card. Make sure the card has a high enough write speed or the entire program will come to a screeching halt as you will run out of memory.
apc mag has a great article detailing out the circuit and code.
http://apcmag.com/arduino-projects-digital-audio-recorder.htm/
There are many things you haven't prepared yet:
output of microphone (assuming you know about electronics: still requires a biasing circuit e.g. a resistor + capacitor).
the output of the microphone is still very weak (in the magnitude of mV), which Arduino is incapable of capturing so you need a pre-amplifier
the design of the pre-amplifier will also include DC offset which makes the output of the microphone all above 0VDC which is in the range of the Arduino ADC otherwise the arduino will capture only those above 0VDC.

how to take /use serial input in verilog?

I want to control a servo motor using an 8-bit input to generate a PWM. Here's my problem: I need to take the serial input through a MAX 232 from PC and I don't know how to do it. A sample code would be helpful too...
TNX
You just need to add a UART (a Universal Asynchronous Receiver/Transmitter) to your FPGA design. Connect the TX and RX signals from the UART to the MAX232, convert them to RS-232 voltage levels, and then connect to the PC. You should be able to find sample code on your own, now that you know what to search for.

spark in arduino,relay and Bluetooth module

My problem is there was a spark when I plug in the voltage source of my 220 V bulb.I have my arduino uno r3,hc-05 Bluetooth Module,Relay Module and 220V bulb.
I cut the wire of my 220V Bulb.
One wire that is near to the bulb was connected to (COM)common connection of our relay.
The other cut was connected to ground.
The Relay Module's VCC was connected to Arduino's 5V.
The Relay's input pin was connected arduino's pin 13 as well as the Normally open(NO) pin of reay.The Relay's ground ws also connected to Arduino's ground.
My Bluetooth module tx was connected to aruino's rx ans Bluetooth module's rx was connected to tx.
I also connected Bluetooth Module,5v to the Arduino's 5v.
and A ground from Bluetooth module to Arduino's Ground.
I made my own version of schematic diagram and this is how it works.It is not that nice but I hoope you will understand.
The small squares serve's as the BreadBoard
https://twitter.com/n_galia/status/419876079403147264/photo/1
Here is a simple relay driver you can use with the Arduino. The component values are not super important, R4 could be larger, R3 can be larger, you can use just about any 5V relay and any NPN transistor. As show it should work with most low/medium sized relay. When active you can check the voltage between Q1's collector and ground. It should be less then a volt. About 4mA is provided by the Ardunio, far below it's output capacity.
PLEASE BE CAREFUL!! you are working with high current and high voltage power. Blowing up an Ardunio is minor compared to the damage you can do to yourself.
The revised schematic might not work either. If your relay is a basic relay a driver will be required. The Ardunio can only sink about 20mA and it's likely your relay will need more to function correctly. The relay coil might look like a short to the Arduino.
If you have a relay with a built in logic level driver or a solid state relay, or even a TRIAC part (not a relay) you might be OK.
In situations like this its advised to use an optical coupler between the Arduino and the relay.
The optical coupler has a transistor that will dive the relay in its output, the transistor is actually a light sensitive transistor (photo-transistor) which is turned on via an LED built into the package. The Arduino would drive this LED (though a limiting resistor) which would activate the transistor to drive the Relay. This way the low voltage electronics are totally protected and isolated from the high voltage stuff.
Ouch!
The Arduino is not compatible of dealing with your 220Vac lines from power and to the light.
Your Arduino may not function correctly anymore.
I have attached a revision to your wiring.

Read digital data directly from a USB port

I use Arduino for comunication between sensors and my C# application using a serial port. Is there any possibility to access digital components directly such as Force Sensitive Resistor - Square, from a USB port?
Do I have to write a driver for that?
I drew a semi-schematic diagram to exemplify:
There isn't a way to directly read an analog sensor over USB since it's a digital bus. You need some sort of processing to convert the analog signal to digital and communicate over the bus properly.
In order to sample information from any sensor, you will need an intermediary. The Arduino uses an FTDI chip to convert UART (Serial) to USB. When you read data over this connection, you are reading it over the Serial over USB interface. My recommendation is to stick with using the Arduino or other micro controller.
If you are really bent on reading it Directly over USB (instead of through the Serial over USB converter) you would have to implement some sort of protocol in a device that supports USB such as the Stellaris Launchpad or an Atmega32U4 AKA Arduino Lenardo. You would also have to write a driver to describe how to communicate with this USB device. Unless you were able to implement it as an already known device such as a keyboard or serial port (Yep, we went full circle there).
In short, there's no already made chip that converts Analog (or Digital) values from a sensor into something any OS would natively understand. Since USB is a protocol much like IP, you're not going to be able to use discreet devices. You're going to have to use a micro-controller with a USB stack.
Again, my advice would be to pass the sensor values over USB through the existing Serial (over USB) port. This is pretty straight forward and easily reproducible without an entire Arduino.
From the looks of the force-sensitive resistor, this is an analog component; the resistance and capacitance changes with the force applied to the sensor. If you check out the FSR installation guide document there are suggested electrical interfaces starting on page 16.
I would recommend the first circuit, connect Vout to an analog input on the Arduino. From there you will need to convert from ADC counts to voltages and then use a lookup table function in the Arduino to convert from voltage to force according to Figure 9. At this point you have a variable containing the force applied to the sensor. From here you can transmit the value over the USB serial bus just like any other value. Your C# application then needs to read the serial data, and parse out the value.

Resources