UART serial access with Rpi 3 - raspberry-pi

I am trying to establish a serial connection between the RPI3 and an Arduino. Because that wasn't working I connected a USB to TTY cable from my laptop to the Rx/Tx pins of RPI. I was eventually able to use PuTTy to connect to it.
I am running Android Things on the RPI and the android code I have running is supposed to be a loopback (reading from UART and writing back what was read).
Here is where I am confused....
When PuTTy connected I was presented with a command line console on the RPI.
How do I get the Rx/Tx pins on the RPI to just be serial connections into and from my application and NOT a way to log into the console?
Is that a bad idea? I suppose if I ever needed to log into the RPI this would make it more difficult...

I figured out what I was doing wrong...
When following the setup directions at the below site I was using the Bluetooth mode instead of the Application mode. When I followed the directions for Application mode I was able to start using UART0 for serial comms
Set the console attribute to the following in cmdline.txt:
console=tty0
Add the following line in config.txt:
dtoverlay=pi3-disable-bt
Remove the following lines from config.txt:
enabled_uart=1
core_freq=400
https://developer.android.com/things/hardware/raspberrypi.html#disabling_the_console

Beginning with Developer Preview 3, in which USB-Serial devices support added, You can use external USB-UART dongles like this instead of UART of Raspberry Pi 3.

Related

How could I make the raspberry pi as a WIFI and ssh module

For a digital design course, we have to use a microcontroller as the CPU of the system. The chip we plan to use is STM32L0C8T6. We want to integrate the SSH function into a keyboard. The way we plan to do it is to connect the STM32 with a Raspberry pi zero or 2 through UART or SPI. The Pi will connect to the WIFI and connect to other hosts through SSH. An LCD display is also connected to the STM32 which will work like the monitor, displaying all things you will see when ssh, like whatever is shown in the terminal when ssh.
My question is how to build the connection between the terminal and STM32. One possible way is to dump everything in the terminal into a file and send the file back to STM32 for display. I think this will be really slow. Are there any better ideas?
The question sounds wired, and I know we could connect LCD directly to the Pi, but this is the project requirement to have to follow. The LCD has to connect to the microcontroller.
Thank you so much!!!!

Catching Probe Requests using monitor mode in Raspberry pi 3

I wanna catch probe requests of mobile devices that are not connected to a network using monitor mode on Raspberry pi 3. I am using Raspbian OS. I used "Wifite" command but it only shows the mac addresses of access points and not of the non connected mobile device. I am a beginner in networking and Raspberry pi. Kindly guide me which commands should I use for this purpose?
You might try looking into sniff-probes.
It switches WiFi channels every two seconds and captures incoming packets using tcpdump.

Configuring i2c on a Raspberry Pi2

I am trying to connect a Temp and Humi probe Adafruit AM2315 and it seams that the only thing I need to do is to get i2c running on my Pi2. I can't seams to find the proper instructions or command line to get it config and running ? Can someone help ?
did you connect it directly to the RPi2 I2C pins, or did you use the 10KOhm resistors too..?
It seems it needs two rapid connections to wake up first, before starting to send commands, see here:
http://raspberrypihobbyist.blogspot.it/2015/02/using-am2315-temperaturehumidity-sensor.html
David

Passive WiFi detection system using WiFi router

As part of my project requirement I want to make a system which will detect all the WiFi devices in my router range either its connected or not, I did some research on it then I found something like wireshark ,kismate etc I just tried the wireshark by making my Mac machine's WiFi as an adhoc network and its all fine I am able to list all the WiFi devices in wireshark, now I want to make a real-time system based on a real WiFi router I don't know how I will configure my router using my PC and how I will monitor the router from my PC , one more thing if I am using this wireshark how I will use this data for my requirement. If any one worked with similar scenarios please help me..thanks in advance
To do that you will need more than the usual API that you have on commercial WiFi routers (by that I mean a full SSH access). I would:
flash my router with OpenWRT (you can search for your router on this page for detailed instructions)
Install the aircrack-ng suite on the flashed router with
opkg update
opkg install aircrack-ng
Put my WiFi card in monitor mode and run the airodump service:
airmon-ng start wlan0 #Put your NIC in monitor mode
airodump-ng mon0 #Sniff surrounding packets
You don't necessarily have to install aircrack-ng, you can just put your card in monitor mode using command line (look at the documentation for your WiFi driver) and then run tcpdump (command line equivalent to wireshark) but aircrack works very well and has a nice format.
Also, I should warn you that you can brick your router by flashing it. I never had such a problem when flashing router mentioned on the OpenWRT wiki and there are (most of the times) ways to restore a bricked router depending on the brand but I am not responsible if you break it ;)

Serial communication with Raspberry pi

How can we do serial communication using the raspberry pi with a python script to send/receive data to my laptop? If yes can we use the RS232 cable to connect to the TX/RX ports on the raspberry pi directly? If yes, what pins must be used from the RS232 cable? It would be help full if anyone can post a example python script?
Since my first aim is to send/receive data to the laptop to/from the raspberry pi, i'm using a RS232 to USB cable at both end to connect to the laptop as well as the raspberry pi.
RS-232/RS-485 to PC and USB to PC
For RS-232
1) Download Putty.
2) Buy a Serial Port RS232 to TTL Converter Module and a RS-232 serial cable for PC.
3) Follow the steps in Connection to a microcontroller or other peripheral on this
link. Actually read the whole thing for better understanding.
4) Power your converter module with either 3.3V (pin 1) or 5.0V (pin 2), connect Rxd pin of the module to Rxd (pin 8) on Rpi and Txd pin to Txd (pin 10) on Rpi.
5) Connect your RS-232 (from PC) cable to the converter module
Now you are ready to do some coding in Python. But before that make sure that you have the library called serial for python to create the communication. You can easliy get it via terminal by typing sudo apt-get install python-serial. Also you will see the baudrate in the code is 7200. It could be less or more depending on the synchronization. Also make sure that baudrate should be same in putty and COM1, which is the port that RS-232 is connected to your PC. You can check and set it from device manager in Windows. By the way, timeout is the time gap between each message you are receiving.
In case you can't run the code from idle (that happens for some libraries), do it in terminal. For that go to the folder where you keep your python code and type python name.py.
import serial
import time
def readlineCR(port):
rv = ""
while True:
ch = port.read()
rv += ch
if ch == '\r' or ch == '':
return rv
port = serial.Serial("/dev/ttyAMA0", baudrate = 7200, timeout = 2)
while True:
rcv = readlıneCR(port)
port.write("I typed: " + repr(rcv))
print(rcv)
For USB serial to PC
You have two options
First, you can buy a USB dongle for RS-232/RS-485 so that you would not use GPIO pins. But it is better to get a USB hub for all mouse, keyboard and dongle.
Second and easier, you can buy a FTDI USB to TTL converter and use GPIOs to have a serial communication with Rpi. The code for this is exactly the same the one with above. Connection for this is easy.
Module -- Rpi
Txd -- > Txd
Rxd -- > Rxd
Gnd ---> Gnd
Are you trying to issue commands to the Raspberry Pi? (like a console?) I would suggest a plain jane 3.3V FTDI cable. You can get them from Digikey or Sparkfun. Note: the Raspberry Pi runs on 3.3V so you must be sure that anything you connect to it is running 3.3V or has a level shifter. See more information about level shifters here. (go down to the Logic voltage levels section)
First, you need to make sure that Raspbian has released the serial console. You can do that with the script located here.
If you're more interested with communicating with other devices then maybe the following suits you:
Do you have an Arduino? You can run a simple test by putting this sketch on your Arduino:
#define SERIAL_BAUD 115200
void setup() {
//Init serial connection
Serial.begin(SERIAL_BAUD);
Serial.setTimeout(1);
}
void loop() {
if ( Serial.available() ) {
byte type = Serial.read();
Serial.write(type);
}
}
And wire it up using the following diagram:
Note: make sure you don't connect a usb cable to the Arduino. It will be powered by the Raspberry Pi.
You can then install and run screen. Screen is a dead simple way of connecting to a serial port.
apt-get install screen
Then run the following:
screen /dev/ttyAMA0 115200
The screen will show up blank. But, when you start typing you will notice that the characters you're writing are getting looped back to your terminal.
Note: If the screen is still blank you should double check the connections (power led on the Arduino is a good thing to check).
When in doubt you can see my whole example here.
The Raspberry Pi's serial port uses 3.3v logic; RS232 uses 12v, so a level shifter would be needed to use those pins so you cannot use RS232 directly.
Serial interfacing in Python using the PySerial module (http://pyserial.sourceforge.net) it is pretty straightforward to send and recieve data. There are examples in the documentation, but essentially to send data:
import serial
port = serial.Serial(portname, baudrate, timeout)
port.write("message to send")
port.close()
It depends what you're doing with the data and what sort of data you're recieving to decide the best way to recieve data, but a very simple example:
import serial
port = serial.Serial(portname, baudrate, timeout)
data = port.read(numberofbytes)
print data
This simply waits until the number of bytes specified has been retrieved or the timeout value is reached.
You can use port.inWaiting() to return how many bytes are currently in the buffer.
you should install python library for serial drivers. you can not use rs232 directly, instead you can use a max232 chip in between rx(gpio15) tx(gpio 14) pins and your usb to serial converter. or you can use usb to ttl serial cable from adafruit. here is the link for setup : http://learn.adafruit.com/adafruits-raspberry-pi-lesson-5-using-a-console-cable/overview
Serial Communication in Raspberry pi.
There are plenty of options for serial communication
Use Visual GDB Plugin in visual studio and deploy code remotely in raspberry pi
and loop back the txd and rxd pins and check if the send message is received or not.
If you are familiar with java Install pi4j and in the example folder there is a sample program , compile and run using terminal. and check the output.
if you are connecting using RS232 and Max232 , please note that uses 3.3 volt not 5 or 12v. , it may burn your board.