How does Arduino Wiring Language work? - arduino

I am new to Arduino and just read from the book < Intel Galileo and Intel Galileo Gen 2 API Features and Arduino Projects for Linux Programmers > that:
In 2003, a student named Hernando Barragan created a hardware thesis
describing an IDE and the integration with circuit boards powered by
micro-controllers. With contributions from other researches the concept
evolved allowing developers to write just a few lines of code in order
to reproduce simple connections of hardware components.
Could anyone explain how software could change hardware wiring as the bold part says?

This is not talking about changing physical wires. It means the code can drive a micro-controller to communicate with the hardware. Each pin of a micro-controller can do different things and speak with different hardware but you do have to physically connect the hardware yourself.
For example:-
To communicate with different hardware, such as a gps, we plug the gps wires into pins of the micro-controller and then use code to monitor the pins. The Arduino will monitor the voltage on the pins to determine power on/off (0's and 1's) and allow you to know the result in your own code. It is similar to morse code but much faster. Eight zero's or 1's gives us one byte, one byte is one letter or number. Wait long enough and we have a whole message (in reality it takes a few milliseconds for quite a big message)
Some hardware uses 0's and 1's as described above, some uses analog values to give readings. For example a temperature sensor, when powered, might produce a voltage between 0 and 5 volts. It would have a wire that plugs into one of the Analog pins on the Arduino. The Arduino code can read the voltage of the temperature sensor connected to an analog pin, perform a bunch of calculations and determine what the temperature is.
Some hardware such as motors and other sensors use more complex messaging systems but all connect to pins of the Arduino micro-controller to be read or written to using the methods described in the specification of the hardware. Normally this involves some quite complex code but Arduino/Wiring is a simple set of instructions that in the background uses the complex code.

Related

Advice needed for connecting multiple arduinos as slave to raspberry pi

I have a project in hand where I need to connect 5 or more arduinos as slaves to Raspberry Pi. Load Cells, Reed Switch, Solenoid lock will be connected to each of the arduino. The arduinos need to send the weight readings when a communication is started by the raspberry pi(master). Only a single arduino will be activated at a time. The arduinos will be placed at a maximum of 6ft distance from the raspberry pi. I need advice regarding how to make this connection. I read that I2C cannot be used for long distances so I am unsure if 6 ft is a long distance for I2C. Next, I am trying to see if a USB would work for my case but the issue is the Pi has only 4 USB slots. So can I use a external USB hub with an external power supply and connected each of the arduinos to the USB hub and provide individual power supply to the arduinos? Will this arrangement work or should I be looking at any other protocol apart from I2C and USB?? Any advice on this will be much appreciated. Thanks a lot for your time.
Arduino (Nano, Uno, Mega etc.) can communicate via SPI, I2C or UART.
Long story short, SPI is not suitable for your application. It is used for fast data transfer over short distances (usually milimeters or centimeters), so mainly for communication between chips mounted on the same PCB or PCBs close together (e.g. display shields).
Using I2C is perfectly fine (let's say up to 10 meters) and in your case it is a way to go. The maximum possible length depends on baud rate, for 10 meters a 9600 baud rate would be OK. The big advantage is that you need only 2 wires to connect all Arduinos, the disadvantage is that only one device can transfer data at the time – in your case, that does not matter.
UART is used for communication with many external modules (GSM, GPS, HMI, ...) and also in combination with USB-TTL chip for communication via USB (virtual COM port). In your case, you can use UART e.g. in combination with external UART-RS485 converter module, but there is no need since you can use I2C.

PWM/PPM Output misses some edges

I am using ESP8266 (NODEMCU 3.0 or something) to make a quadcopter. Ive connected ardu pro mini to RC receiver so I am reading PPM values from it. Pro mini sends data with tx to ESP8266. ESP reads it with software serial with 115200 baudrate. I am communicating with MPU9255 (Waveshire) via I2C either.
My problem is that I cant fully controll my brushless motors. When I was using arduino instead of ESP8266, servo library was the best and reliable. But ESP's servo library is different, since its not AVR, and problems occurs. First of the servo library didnt want to work on most frequencies. I mean default is 50Hz (20000uS) and in this state ESC of motors did armed but unfortunatelly when changes was fast and short (1250-> 1370 -> 1250) it did miss that change like nothing happnd... This makes my D value in PID controller useless...
Sometimes on 100Hz freq all was working fine, but sometimes not...
When Ive started to use analogWrite only 500Hz was working fine, rest of freq didnt want to arm ESCs.
PS. I am using 3.3V to 5V converter for PPM/PWM pins so I am sure that the signal is fine for ESCs.
PS2. I dont have any osciloscope unfortunately.
The ESP82266 present on your module is a RF transceiver integrated circuit that can handle WiFi communication, both configured as a slave to a microcontroller such as the ones present on various Arduino boards, or as a standalone chip by having it's on-board Tensilica L106 32-bit processor programmed via an external SPI flash memory. If used as a slave, the communication between, for example, an Arduino an the ESP82266 can be done using different protocols such as SPI / SDIO or I2C / UART interfaces. Googling a comprehensive Tensilica L106 user guide on the internet doesn't seem an easy task, and it looks as if some people have already failed to find it. If you're seeking to add Wi-Fi capabilities to your quadcopter the solution I suggest is having the Arduino take control over the servos, motors, etc. and hand off messages via SPI to your ESP82266 module. If this isn't the answer you are looking for, please try to be clearer about it, maybe find someone to do as an English translator for you.
However, if this is what you're concerned about, and you would like to use the ESP82266 module as as standalone solution, please link its built-in processor datasheet and the relevant parts of the quadcopters code that might need debugging.

AVR Atmega8 Serial Communication

I am posting this question after not getting any sort of help across the web and reading many articles and tutorials. I ended up asking questions with hope of getting guided.
DESPERATE FOR HELP.
What i want:
1) I want to build a R/C tank.
2) Basically its not controlled by a remote control but i want control by a laptop.(i could write a c++ or c# program).
What i know:
1) I know how to develop a development board. (i want to develop my own, not use arduino)
2) I know c++ and assembly very well.
3) I know about AVR's ALU, Memories(all 3), Stack, Interrupts, IO Operations well.
4) I know theory about how SPI, RS232, UART works.
PROBLEMS: (I have many questions, but most important are)
1) B/c i have made my own board. How can i transfer my program(hex file) to my board(i seek practical and physical implementation, not theory please)(i know about a 6-pin ISP but not clear about practical implementation)
2) After it, how can i make wireless communication b/w my AVR and laptop.(hardware device?)(SPI, RS232, UART?)
MAIN CONFUSION:
1) I cannot help myself differentiating or relating SPI, RS232 and UART.
I know these are used for serial communication between devices but how?(which is used when and why and how)(appropriate hardware for transmitting device and receiving device)
THING TO KNOW:
1) I haven't started making my board and programming it because i think i should learn everything first and then do it in a one go. OR should i start practical work and things get easier automatically??
2) I learnt a tutorial series on Serial Communication from http://maxembedded.com/2013/09/serial-communication-introduction/ the starting 5 topics leaving the last one(I2C). Am i missing something there?
I hope everything is clear, and waiting for a good-men's words.
Note: I am already very misguided and lost, so i want experienced and expert's guidance. Many Many Many Many Thanks in Advance.
MY BOARD LOOKS LIKE:
http://www.robotplatform.com/howto/dev_board/schematic_l/38.jpg
1) To upload your code into AVR chip, you can use ISP interface. That requires you to connect at least 5 pins: SCK, MISO, MOSI, RESET, GND, and optionally VCC (it used to control or supply voltage, but not mandatory, if your board has it's own power supply). All you need is just to wire 6- or 10-pin ISP connector to that pins of your CPU.
To begin programming process you need to obtain some programmer device (USBasp, AVRISPmk2, STK500/600 etc.), Also, you can use Arduino board itself as ISP-programmer for external AVR chip, like this: http://www.instructables.com/id/Programming-an-ATTiny13A-using-Arduino-servo-int/
Each of programmer model requires it's compatible software (such as PonyProg), for example STK500 and AVRISP programmes could be used directly from Atmel Studio.
Also, you can connect ISP to parallel (LPT) port of the PC, and upload firmware using specialized software, such as uniprof
Another way to upload software - it is to make your own bootloader - a tiny program that will update firmware, using any available interface.
2) USART, SPI, I2C - it is different interfaces to communicate with peripherals. Note that RS232 - it is electrical interface built over USART. I.e. you need external IC which will convert USART logical level signals to RS232 electrical levels.
each of that interfaces have it's own profs and cons. And usually selection of which interface to use depends on which interface is supported by peripherals.
SPI - it is interface for high-speed communication. One master many slaves. It requires a lot of wires: MISO (data from master to slave), MOSI (data from slave to master), SCK (clock) - those three could be common for all slaves. Also it requires a SS (slave select) - one SS wire for each slave to determine which slave is in communication at the moment, also it sets the edges of the data packet.
USART - it is common interface, to communicate two chips. Each byte transmitted with foregoing start bit, optional parity and following stop bit. I.e. transfer has a quarter overhead, but byte can be transmitted in any moment.
Works in synchronous and asynchronous modes. Asynchronous mode requires only 2 wires (RX and TX, not counting GND that also required). This mode requires that receiver and transmitter to be sychronized, in most cases that required to crystal oscillator to be installed.
Synchronous mode works in the same format as asynchronous, but have additional XCK (clock) wire, that determines in which moments bits are possible to be transmitted. This allows to increase transmission speed and not requires time precision from receiver. Synchronous mode is rare used.
I2C - it's a bus with only two wires, allows many masters and many slaves. Utilizes pull-up resistors to achieve wired AND, have it's own algorithm to detect collisions, more complicated to be programmed, transmission speed is limited.
Often used by peripherals, such as accelerometers, RTCs etc.
AVR chips have no it's own support for wireless communication, therefore, to do that you need to use some external wireless chip, for example bluetooth, or WiFi, there are a lot of such modules (for example ESP8266). AVR chip communicate with them using USART, sending and receiving simple commands.

PWM read with Arduino MEGA and Ethernet Shield

I'm on a project in which I must read the DC (1ms-2ms) of 16 PWM signals with 4 Arduino MEGA 2560, 4 PWM for each one. After have read it, I should send the 16 values to a computer. The initial idea was to use 4 Arduino Ethernet Shield connected to a router and then get on the computer. The other option is to connect the 4 Arduino directly by USB to the computer and perform it with each Serial.print. Which of the two options could give me better results? I have to emphasize that time is important, less than 20ms to receive the 16 PWM values would be optimal.
A greeting and thanks.
20ms is not really an issue here. Assuming you connect the Arduino over USB, using Serial, at 115,000bps, you can send the 4 bytes (Assuming a byte per Duty Cycle reading) to the control computer in .35ms.
Using TCP/IP, and a direct Ethernet connection, it will be orders of magnitude faster than that.
So, I would say, what are you more comfortable with in coding terms? The serial approach will be easy on the Arduino, but you might have to work a bit harder on the control computer. (For instance, will you use C++, and a Serial library like Boost::ASIO ?
Or, are you comfortable with TCP/IP socket programming? And if so, you will have a more robust solution, which will scale better for you.

Gathering/reading data from sensors on two different baud rates with Arduino

I want to use an Arduino to gather data from two sensors. This seems easy when the required baud rate for two sensors is the same. However, I'm stumped as how to go about doing this when two different rates are required.
For example, suppose I want to use a barometer and a GPS sensor at the same time. I imagine I'd have to modify something lower-level for one of the sensors (possibly in the libraries or supporting functions), but where do I begin?
Having a look at the provided material, I can see that your hardware use serial communications. The barometer uses an I²C port and the GPS a serial port.
The "communication speed" (or baud rate) does not have to be exactly the same for all devices. Indeed, your sensors may have different sample rate or different needs, and thus does not need to communicate with the central unit with the same frequency.
I would suggest to go step by step. Try first with the GPS sensor. I think serial ports are easier to start with. Try first (a) to communicate directly with the GPS through your computer (you can use your Arduino to set up a USB-serial connection), and later (b) try to write some code which communicates in the same way with the GPS but now from Arduino.
Simple method for Doing this. You have two Serial Port
SoftwareSerial
hardwareserial
In software Serial is one You communicate Directly . in hardware serial you configured for particular pin as Tx and Rx pin. SO barometer you can use SoftwareSerial and for GPS you can use Hardware Serial.
[1]: http://arduino.cc/en/Reference/SoftwareSerial
[2]: http://forum.arduino.cc/index.php?topic=49645.0

Resources