I have a raspberry pi3 and a working board. I'd like one as a i2c master(pi3), and another one is slave(working board).
I'd like to read/write to working board from pi3.
I found it on the Internet.
https://www.spinics.net/lists/linux-i2c/msg30208.html
Following this steps.
I set CONFIG_I2C_SLAVE=y, CONFIG_I2C_SLAVE_EEPROM=y and CONFIG_I2C_CHARDEV=y to kernel of my working board, and set
# echo slave-24c02 0x1064 > /sys/bus/i2c/devices/i2c-1/new_device
[ 233.396818] i2c i2c-5: new_device: Instantiated device slave-24c02 at 0x64
#
I ran the i2cdetect.
I can see the 0x64 device from my working board, but my pi3 can not see it.
(working board)# i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- UU -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
(p3)# i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
I just connect SDA1 and SCL1 to working board from pi3.
How to fix it?
my pi3
kerenl: 4.19.97-v8(buildroot-2020.02.8)
Thanks
Related
I have a an AM2320 connected, and its address are as follows i2c_bus=1, i2c_addr=0x5c, i2c_slave=0x0703. I wrote code on the raspberry pi and it all works. I know there are is a device at 0x48, and I am not sure about 0x40, but when I run the command i2cdetect -y 1 I get
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: 40 -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Why don't I see the 0x5c device?
$ i2cdetect -r -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
$ i2cset -y 1 0x50 0xff 0x21
$ i2cget 1 0x50 0xff
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-1, chip address 0x50, data address
0xff, using read byte data.
Continue? [Y/n] Y
0x20
It’s detected fine, but set, get are not working in 24lc512.
I'm attempting to read data from the VL53L1X-SATEL and the TSL2561 Luminosity Sensor at the same time using I2C on the Raspberry Pi 3 B+. When just the vl53l1x is connected I get the following from i2cdetect -y 1:
pi#BIKE_SENSOR_SYSTEM:~ $ i2cdetect -y 1
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- 29 -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
With just the tsl2561 connected I get:
pi#BIKE_SENSOR_SYSTEM:~ $ i2cdetect -y 1
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- 39 -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
This is as expected.
From what I've read online, in order for them to work together the two devices should be connected in parallel to the corresponding pins on the pi. However, when I do this I get:
pi#BIKE_SENSOR_SYSTEM:~ $ i2cdetect -y 1
00: -- -- 05 -- -- -- -- -- -- -- -- -- --
10: -- -- -- 13 -- -- -- -- -- -- 1a -- -- -- 1e --
20: 20 -- -- -- -- -- 26 -- -- -- -- -- -- -- -- 2f
30: -- -- -- -- -- -- -- -- -- 39 -- -- 3c -- -- --
40: -- -- -- -- -- 45 -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: 60 -- 62 -- -- -- -- -- 68 -- -- -- -- -- -- 6f
70: -- -- -- 73 -- 75 -- --
This changes each time I run i2cdetect -y 1 with only the 39 remaining constant. What do I have to change for i2cdetect to display only the 29 and 39?
Here is how I am connecting the pins:
I want to copy a .csv file into a postgresql table, where the file name is a variable. It fails with a "no such file or directory" error if \COPY and a user other than postgres is used. However, the copy succeeds if COPY and the postgres user is used.
The failing script:
martin#opensuse1:~> ./test1.sh
Null display is "¤".
'/home/martin/20180423.csv'
psql:load.sql:2: :load_csv: No such file or directory
martin#opensuse1:~> cat test1.sh
load_csv=/home/martin/20180423.csv
psql -d test1 -e -f load.sql --variable=load_csv="'$load_csv'"
martin#opensuse1:~> cat load.sql
\echo :load_csv
\copy test_table (col1, col2, col3) FROM :load_csv delimiter ';' encoding 'LATIN1' NULL '';
martin#opensuse1:~>
The working script:
martin#opensuse1:~> ./test1.sh
Null display is "¤".
'/home/martin/20180423.csv'
copy test_table (col1, col2, col3) FROM '/home/martin/20180423.csv' delimiter ';' encoding 'LATIN1' NULL '';
COPY 3
martin#opensuse1:~> cat test1.sh
load_csv=/home/martin/20180423.csv
psql -w postgres -d test1 -e -f load.sql --variable=load_csv="'$load_csv'"
martin#opensuse1:~> cat load.sql
\echo :load_csv
copy test_table (col1, col2, col3) FROM :load_csv delimiter ';' encoding 'LATIN1' NULL '';
martin#opensuse1:~>
What can I do to make this script run without having to use the postgres user?
Martin
It seems that the psql variables are not substituted in the \copy command.
A solution is to write the \copy command to a file and execute that file.
The part from my script (load the table par from the tsv-file with the
name stored in :input_file) is:
-- Tuples only:
\t on
-- Output file:
\o load_cmd.sql
select concat('\copy par from ''', :'input_file', '.tsv'';');
-- Standard output again:
\o
-- Normal decoration of tables:
\t off
-- Now execute the file with the \copy command:
\i load_cmd.sql
I have the following (massaged) psql script invoked from a bash shell:
foo=$( psql -q -t -R $'\x01' -F $'\x02' \
--variable="title=something" \
--variable="severity=level9" \
--pset='format=unaligned' \
<<'EOF'
SET standard_conforming_strings=on;
SET myvars.title = :title;
SET myvars.severity = :severity;
DO $$
BEGIN
IF EXISTS ( SELECT 1 from my_database
WHERE title=current_setting('myvars.title') \
AND severity=current_setting('myvars.severity') )
THEN
RAISE NOTICE 'Found existing entry';
ELSE
RAISE NOTICE 'Did not find existing entry';
END IF;
END;
$$;
EOF
)
I was hoping to capture in the bash variable "foo" some indication of whether or not the query succeeded. I thought I could add some kind of print/echo/return/whatever statement after each of the RAISE NOTICE statements to output 0 or 1 from the psql statement so it could be captured in foo for later evaluation in the bash script, e.g.:
foo=$( psql -q -t -R $'\x01' -F $'\x02' \
--variable="title=something" \
--variable="severity=level9" \
--pset='format=unaligned' \
<<'EOF'
SET standard_conforming_strings=on;
SET myvars.title = :title;
SET myvars.severity = :severity;
DO $$
BEGIN
IF EXISTS ( SELECT 1 from my_database
WHERE title=current_setting('myvars.title') \
AND severity=current_setting('myvars.severity') )
THEN
RAISE NOTICE 'Found existing entry';
magical_incantation 1;
ELSE
RAISE NOTICE 'Did not find existing entry';
magical_incantation 0;
END IF;
END;
$$;
EOF
)
I've been reading psql documentation for about the past 5 hours and cannot figure out the command/syntax of my imaginary magical_incantation above.
I am new to psql and tweaking someone else's code. I cannot change the main structure of the script, I just need some way to print a value.
Can anyone point me in the right direction?
\echo prints to stdout in psql. I think RAISE NOTICE goes to stderr.
It is possible to select into a psql variable and then echo it. A basic run-down is at How do you use script variables in PostgreSQL?
However I am not sure of any way to pull a query result into a variable at present.
Assuming that is not the answer you are looking for is just a SELECT.
So something like:
SELECT (EXISTS (....))::int;
-- true is 1, false is 0
Note there is no way to do this from a DO statement so you would have to actually create a function if you need to do this from plpgsql.